新手到JQuery/JSON/AJAX所以请好。与发送阿贾克斯消息的问题
我已经把SO和其他网站上的例子拼凑在一起,但我很挣扎。
我已经创造了一些函数来处理Ajax响应...
function newOrderSuccess(response) { ... }
function newOrderTimeout() { ... }
function newOrderFail() { ... }
...
这里是AJAX调用:
function sendCallAjaxUsingJson(theUrl, theData, successCallbackFunction, timeoutCallbackFunction, otherErrorCallback, timeoutValueMilli)
{
var successFn = successCallbackFunction;
var timeoutFn = timeoutCallbackFunction;
var otherFn = otherErrorCallback;
if(!(typeof successFn === 'function') || !(typeof timeoutFn === 'function') || !(typeof otherFn === 'function'))
return false;
$.ajax({
type: "POST",
url: theUrl,
timeout:timeoutValueMilli,
dataType: 'json',
data: { json: JSON.stringify(theData) },
success:successFn(result),
error: function(x, t, m) {
if(t==="timeout") {
timeoutFn();
} else {
otherFn();
}
}
});
}
我的代码调用如下函数:
sendCallAjaxUsingJson("/ordertaker.php", 'submitOrder','newOrderSuccess', 'newOrderTimeout', 'newOrderFail',1000);
结果是.....什么也没有。在上传ordertaker.php
文件之前,我正在使用newOrderFail()
函数,但现在我什么都没有。
我哪里错了?
请从您的浏览器控制台发布错误。什么是'sendCallAjaxUsingJson'?它应该是“doCallAjaxUsingJson”吗? – 2013-03-20 21:39:08
什么是什么?您是否看到fiddler/firebug的外拨电话?或者它从未初始化该呼叫?如果你遇到错误,那是非常有价值的 – 2013-03-20 21:39:14
@JacobParker对不起,我正在简化我的代码以删除相关的组件。它应该是doCallAjaxUsingJson,如你所说。我更新了它。 – NEW2WEB 2013-03-20 21:42:34