Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 发送ajax消息时出现问题_Javascript_Ajax_Json - Fatal编程技术网

Javascript 发送ajax消息时出现问题

Javascript 发送ajax消息时出现问题,javascript,ajax,json,Javascript,Ajax,Json,JQuery/JSON/AJAX的新手,所以请友好一点 我从SO和其他网站的例子中拼凑出了这幅作品,但我很挣扎 我已经创建了一些函数来处理AJAX响应 function newOrderSuccess(response) { ... } function newOrderTimeout() { ... } function newOrderFail() { ... } 以下是AJAX调用: function sendCallAjaxUsingJson(theUrl, theData, suc

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()
函数,但现在什么也没有得到


我哪里出错了?

您正在使用JSON而不是函数将字符串传递给
sendcallajax

sendCallAjaxUsingJson("/ordertaker.php", 'submitOrder',newOrderSuccess, newOrderTimeout, newOrderFail,1000);
另外,在ajax调用中调用success函数,而不是设置它

success:successFn,

请从浏览器控制台发布错误。什么是
sendCallAjaxUsingJson
?它应该是
doCallAjaxUsingJson
?什么是无?你在fiddler/firebug中看到一个出站呼叫吗?或者它从未初始化呼叫?如果你遇到了一个错误,那是非常严重的valuable@JacobParker对不起,我只是稍微简化了我的代码,去掉了相关的组件。正如你所说,它应该是doCallAjaxUsingJson。我更新了。其他的函数在做什么?调用某个Web服务?不,我使用的另一个函数是因为我正在阅读某个可以发送
函数(response{successFn(response);}
作为一个参数,因此我创建了一个名为:
sendCallAjaxUsingJson
的中间函数来截取您指出的一些项目,这让我更接近了。现在它可以用于超时,但我无法运行success函数。它现在只运行fail(错误)服务器上的脚本只有一个echo语句,所以不应该返回“success”吗?