php - Parsing Json in JQuery get error "ReferenceError: href is not defined" -


when try parse json connection.php , using jquery :

<!doctype html> <html>  <head>     <script type="text/javascript" src="jquery-2.1.1.js"></script>     <script type="text/javascript">     $("document").ready(function() {         $.getjson('connection.php', {             cid: href,             format: 'json'         }, function(data) {             $.each(data, function(index, element) {                 /* mengisikan table dari hasil json */                 $('#tabledata').find('tbody')                     .append($('<tr>')                         .append(                             '<td>' + data.sys + '</td>' +                             '<td>' + element.procid + '</td>'                         )                     );             });         });     });     </script> </head>  </html> 

i got error :

referenceerror: href not defined $.getjson('connection.php', { cid:href, format:'json' }, function(data) {

use quotes around href if want send cid value string href.

$.getjson('connection.php', { cid: 'href', format:'json' }, function(data) { //                                 ^    ^ 

if href variable, make sure in scope of getjson.

$("document").ready(function() {     var href = 'www.google.com'; // defined here      $.getjson('connection.php', { cid:href, format:'json' } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -