Jak*_*GIS 5 javascript ajax jquery
我的问题是关于$.ajax()jQuery方法.我无法获得成功参数$.ajax().
这有效:
$.ajax({
type: 'POST',
url: "/getCodes.php?codes=billingCodes&parent="+$('#wClient').val(),
dataType: 'json',
success: window.alert("inside aJax statement")
});
Run Code Online (Sandbox Code Playgroud)
这不是:
$.ajax({
type: 'POST',
url: "/getCodes.php?codes=billingCodes&parent="+$('#wClient').val(),
dataType: 'json',
success: function(){
window.alert("inside aJax statement");
}
});
Run Code Online (Sandbox Code Playgroud)
在第一种情况下,我得到一个JavaScript警报窗口,让我知道$.ajax()我调用的工作正常.在第二个代码块中所有改变的是我把window.alert()里面的一个function() { window.alert(); }.
这一点的目的是验证$ .ajax是否正在运行,这样我就可以function(){}在$ .ajax成功运行时添加一些实际有用的代码.
在您的第二个示例中,除非您从服务器成功回拨,否则不会发生任何事情.添加一个错误回调,正如许多人建议的那样,确实ajax请求确实有效,但服务器当前没有发送有效的响应.
$.ajax({
type: "POST",
url: "/getCodes.php?codes=billingCodes&parent="+$('#wClient').val(),
dataType:"json",
success: function(response){
alert(response);
},
error: function(jqXHR, textStatus, errorThrown){
alert('error');
}
});
Run Code Online (Sandbox Code Playgroud)
有用的链接跟踪错误.