Javascript 由于某些原因,AJAX请求没有得到结果
由于某些原因,这没有得到任何结果,我不确定我是否使用了“数据:”对。 我试着搜索了一段时间,但似乎我不能解决这个问题,我在js方面相当差Javascript 由于某些原因,AJAX请求没有得到结果,javascript,jquery,ajax,Javascript,Jquery,Ajax,由于某些原因,这没有得到任何结果,我不确定我是否使用了“数据:”对。 我试着搜索了一段时间,但似乎我不能解决这个问题,我在js方面相当差 PHP脚本运行100%正确,请使用html脚本帖子进行尝试。您的语法错误完成和失败应分别为成功和错误 因此,它应该是: var id = -1; function addMSG(dataz) { console.log(dataz);
PHP脚本运行100%正确,请使用html脚本帖子进行尝试。您的语法错误<代码>完成和
失败
应分别为成功
和错误
因此,它应该是:
var id = -1;
function addMSG(dataz) {
console.log(dataz);
}
function waitForMsg() {
console.log("start waitmsg");
$.ajax({
url: "chatxml2.php",
type: "POST",
async: true,
cache: false,
timeout: 1000,
data: {id: id, chat: '.filter_input(INPUT_GET,"id").'},
datatype: "xml",
done: function(dataz) {
//addmsg(nera reikia);
addMSG(dataz);
console.log("success");
},
fail: function(XMLHttpRequest, textStatus, errorThrown){
//addmsg("error", textStatus + " (" + errorThrown + ")");
waitForMsg();
console.log("fail");
}
});
}
$(document).ready(function(){
console.log(id);
waitForMsg();
});
如果要使用延迟语法,则应为:
$.ajax({
url: "chatxml2.php",
type: "POST",
async: true,
cache: false,
timeout: 1000,
data: {id: id, chat: '.filter_input(INPUT_GET,"id").'},
datatype: "xml",
success: function(dataz) {
//addmsg(nera reikia);
addMSG(dataz);
console.log("success");
},
error: function(XMLHttpRequest, textStatus, errorThrown){
//addmsg("error", textStatus + " (" + errorThrown + ")");
console.log("fail");
}
});
成功替换完成,错误替换失败
阅读aviable done and fail的延迟对象。
$。ajax
不会读取选项对象上的done:
和fail:
属性。使用fixit:function(){alert(“hi”);}
也不会做任何事情。
$.ajax({
url: "chatxml2.php",
type: "POST",
async: true,
cache: false,
timeout: 1000,
data: {id: id, chat: '.filter_input(INPUT_GET,"id").'},
datatype: "xml"
}).done(function() {
addMSG(dataz);
console.log("success");
}).fail(function() {
console.log("fail");
});