【发布时间】:2021-05-02 21:33:36
【问题描述】:
我正在使用此代码:
$.ajax({
type: 'post',
url: "http://www.localhost/do_getmemes.php",
dataType: 'json',
data: {userid: userid, lastid: lastID},
success: function(data) {
console.log('bla');
console.log(data);
}
});
在do_getmemes.php 内部,post 参数被成功接收,json 正在生成,但我在success 上没有得到它??控制台没有显示任何内容。它在网站上运行良好,但在使用 XAMPP 的本地主机上却不行
这一切都在php文件中工作,这是最后:
file_put_contents('test.json', json_encode($array)); // file generated and not empty
echo json_encode($array);
这里有什么问题?
编辑:
AJAX 通常有效,我通过获取简单字符串进行测试:
$.ajax({
url: "http://www.localhost/contact/text.php",
success: function(data) {
console.log(data) // got it
}
});
【问题讨论】:
-
错误日志没有显示这个 php 文件的任何内容,我不知道为什么会这样,因为 json 是生成的而不是空的
-
http://www.localhost/do_getmemes.php?将代码转移到问题时,这是否被破坏了? -
您是从文件系统还是从 XAMPP Web 服务器加载页面? AJAX 不能在文件系统中工作。
-
我在装有 Windows 10 的电脑上使用 XAMPP。AJAX 确实有效,我通过获取简单文本对其进行了测试,请在 1 分钟内检查问题的更新
标签: javascript php jquery ajax xampp