我正在尝试通过ajax和php调用一些数据库数据。但是ajax调用不起作用,我无法在网络上找到解决方案。
所以这是我的代码:
test.php
include_once 'db_class.php';
$cat = $_GET['cat'];
$dbconn = new dbconn('localhost', 'root', 'somepsw', 'blog');
$dbconn->set_query("select * from posts where category = '".$cat."'");
echo '
'.$dbconn->query.'
';
$result = $dbconn->result;
$num = $dbconn->num_results;
$array = mysqli_fetch_assoc($result);
echo json_encode($array);
?>
如果我在浏览器中键入该网址: http://127.0.0.1:82/blog/ws/test.php?cat=css
通过jsonEncode返回的数据是正确的,但是当我使用jquery将其加载到html页面时,他无法读取数据。
test.html
function ajaxCall() {
var css;
$.ajax({
url: 'test.php',
type: "GET",
data: {cat: css},
dataType: 'json',
success: function(rows)
{
alert(rows);
},
error: function() { alert("An error occurred."); }
});
}
ajaxCall();
提前致谢。
425

被折叠的 条评论
为什么被折叠?



