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
Post a Comment