0

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);

结果……什么都没有。newOrderFail()在上传文件之前,我正在使用该功能ordertaker.php,但现在我什么也没得到。

我哪里做错了?

4

1 回答 1

1

您将字符串传递给sendCallAjaxUsingJson而不是函数,

sendCallAjaxUsingJson("/ordertaker.php", 'submitOrder',newOrderSuccess, newOrderTimeout, newOrderFail,1000);

此外,您在 ajax 调用中调用您的成功函数,而不是设置它。

success:successFn,
于 2013-03-20T21:48:46.410 回答