php-f / var/www/html/test-json.php
[ {title:"",
content:"",
author:"",
email:"sanyo@tom.com",
ip:"59.51.24.37"}
, {title:"",
content:"<img alt="" src="upfiles/54591303758197437.jpg" />
<img alt="" src="upfiles/20130714_121621_2779.jpg" />
<img height="46" alt="" width="615" src="/php/8/example/8.1/fckeditor/editor/filemanager/connectors/php/upfiles/20130714_123447_8018.png" />
",
author:"",
email:"shemo@qq.com",
ip:"201.11.43.45"}
, {title:"",
content:"",
author:"",
email:"tdkd@163.com",
ip:"89.12.34.56"}
, {title:"",
content:"",
author:"",
email:"xta@tom.com",
ip:"202.103.56.6"}
now, I want to call this test-json.php, with another test-json.html and output the result.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="http://127.0.0.1/jquery-3.3.1.min.js"></script>
<h2 align="center">Ajax</h2>
<table>
<tbody id="disp">
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tbody>
</table>
<script>
$(function(){
$.getJSON("test-json.php", function(data) {
$.each(data,function(i,item){
var tr = "<tr><td>" + item.title + "</td>" +
"<td>" + item.content + "</td>" +
"<td>" + item.author + "</td>" +
"<td>" + item.email + "</td>" +
"<td>" + item.ip + "</td></tr>"
$("-sharpdisp").append(tr);
});
});
});
</script>
</body>
</html>
the test-json.html above did not report an error, but why did it not display the data?
changed the code to add the + sign, which is not what linong said.