您现在的位置是:主页 > news > 建设门户网站申请/网络公司推广公司
建设门户网站申请/网络公司推广公司
admin2025/5/2 12:21:07【news】
简介建设门户网站申请,网络公司推广公司,盐城做网站的公司地址,大庆市工程建设信息去哪个网站我正在尝试通过ajax和php调用一些数据库数据。但是ajax调用不起作用,我无法在网络上找到解决方案。所以这是我的代码:test.phpinclude_once db_class.php;$cat $_GET[cat];$dbconn new dbconn(localhost, root, somepsw, blog);$dbconn->set_query(…
我正在尝试通过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();
提前致谢。