当我尝试从connection.php解析json时,使用的是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>
我得到错误:
ReferenceError:href未定义$.getJSON('connection.php',{cid:href,format:'json'},函数(数据){
cid
值作为字符串href
发送,请在href
周围使用引号。
$.getJSON('connection.php', { cid: 'href', format:'json' }, function(data) {
// ^ ^
如果href
是可变的,请确保它在getJSON
的范围内。
$("document").ready(function() {
var href = 'www.google.com'; // Defined here
$.getJSON('connection.php', { cid:href, format:'json' }