【发布时间】:2021-11-04 06:20:12
【问题描述】:
我的问题是关于$.ajax() jQuery 方法。我无法让$.ajax() 中的成功参数工作。
这行得通:
$.ajax({
type: 'POST',
url: "/getCodes.php?codes=billingCodes&parent="+$('#wClient').val(),
dataType: 'json',
success: window.alert("inside aJax statement")
});
这不是:
$.ajax({
type: 'POST',
url: "/getCodes.php?codes=billingCodes&parent="+$('#wClient').val(),
dataType: 'json',
success: function(){
window.alert("inside aJax statement");
}
});
在第一种情况下,我得到一个 JavaScript 警报窗口,让我知道我调用的 $.ajax() 正在工作。第二个代码块中的所有更改是我将window.alert() 放在function() { window.alert(); } 中。
这样做的目的是验证 $.ajax 是否正在运行,这样当 $.ajax 成功运行时,我可以在 function(){} 中放入一些实际有用的代码。
【问题讨论】:
-
“这行得通:” 不,不行。
-
添加一个错误回调并给我们三个传入参数的值。
-
你确定你没有在
localhost上运行吗? 并且你确定调用的url(“/getCodes.php?etc..”)是正确的吗? -
我绝对在本地主机上运行。是的 getCodes.php 是正确的,我可以看到 getCodes.php 产生的变化。
-
是 getCodes.php 返回有效的 json
标签: javascript ajax jquery