我不明白为什么Ajax没有在此函数中调用成功或错误:
function get_cust_key(custid) {
$.ajax({
type: "POST",
url: 'http://localhost/Test/index.php/getCustomerkey/' + custid,
async: false,
contentType: "application/json; charset=utf-8",
dataType: 'json',
sucsess: function(result) {
alert("success");
console.log(result)
},
error: function(result) {
alert("error");
consloe.log(result);
}
});
}
我应该收到成功或错误警报消息,但我什么也没收到。如果我将不存在的网址设为:
url: 'http://localhost/Test/index.php/something/'+custid,
然后我收到错误警报消息。
使用正确的链接可以正常工作。如果我使用调试器,则可以看到带有“ custid”的链接返回具有正确(预期)json数据的结果(200),但是由于某种原因,该结果未启动成功调用,并且未收到成功警报消息。在控制台日志中,我没有收到任何错误消息。我已经尝试过此代码:
$.post('http://localhost/Test/index.php/getCustomerkey/' + custid, function(data, status) {
alert("Data: " + data['data']['0']['custkey'] + "\nStatus: " + status);
console.log(data);
});
由于某种原因,它的警报窗口起作用,我还从json status == success中获取数据。
任何想法,为什么我的顶级代码无法正常工作,为什么我没有获得成功或错误警报...