Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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
Ios 回调不';JQuery移动多页面中的t fire_Ios_Jquery_Jquery Mobile_Cordova - Fatal编程技术网

Ios 回调不';JQuery移动多页面中的t fire

Ios 回调不';JQuery移动多页面中的t fire,ios,jquery,jquery-mobile,cordova,Ios,Jquery,Jquery Mobile,Cordova,我对这一点很感兴趣。我有一个.html页面来表示我的移动应用程序的主页。在同一个html页面中,我定义了一个页面作为登录屏幕。显示登录屏幕的逻辑工作正常…我的问题是我有一个带有以下签名的登录函数 ajaxLogin(credentials, successCallback, failureCallback) { $.ajax({ url: SERVER_API + '/login', data: credentials,

我对这一点很感兴趣。我有一个.html页面来表示我的移动应用程序的主页。在同一个html页面中,我定义了一个页面作为登录屏幕。显示登录屏幕的逻辑工作正常…我的问题是我有一个带有以下签名的登录函数

ajaxLogin(credentials, successCallback, failureCallback) {
    $.ajax({
            url: SERVER_API + '/login',
            data: credentials,
            type: 'post',
            async: true,
            beforeSend: function () {
                $.mobile.showPageLoadingMsg(true);
            },
            always: function () {
                console.log('always');
                $.mobile.hidePageLoadingMsg();
            },
            done: function (data, status, xhr) {
                console.log('login: ok'); //< -- This never fires but I can see that the server returned a 200 in Safari's developer menu
                successCallback();
            },
            fail: function (request, error) {
                failureCallback(); // <-- This function is never executed when I send bad login info. But again, the server is returning an error status code
            }
        });
}
ajaxLogin(凭证、成功回调、失败回调){
$.ajax({
url:SERVER_API+'/login',
数据:凭证,
键入:“post”,
async:true,
beforeSend:函数(){
$.mobile.showPageLoadingMsg(true);
},
始终:函数(){
console.log('always');
$.mobile.hidePageLoadingMsg();
},
完成:功能(数据、状态、xhr){
log('login:ok');//<--这不会触发,但我可以看到服务器在Safari的开发者菜单中返回了一个200
successCallback();
},
失败:功能(请求、错误){
failureCallback();//beforeSend函数是jQuery Ajax设置jQuery.Ajax([settings])的一部分。但是,always、done和fail是jqXHR对象的承诺方法。在您的示例中,您使用always、done和fail作为设置,这是不正确的

$.ajax({
    url: "http://.....",
    beforeSend: function (xhr) {
        // code
    }
}).done(function (data) {
    // do something
});

您可以在中找到更多信息。

我认为您在寻找“成功”和“错误”,即:

然后,您可以在最初调用此函数时处理成功/失败:

ajaxLogin(
    credentialsData, //data you're passing to the function
    function (data)
    {
        //stuff to do on success
    },
    function (jqXHR, statusText, errorThrown)
    {
        //stuff to do on failure
    }
);
ajaxLogin(
    credentialsData, //data you're passing to the function
    function (data)
    {
        //stuff to do on success
    },
    function (jqXHR, statusText, errorThrown)
    {
        //stuff to do on failure
    }
);