gpt4 book ai didi

javascript - jQuery Ajax 在 cordova iOS 应用程序上发送之前触发成功

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:21:35 24 4
gpt4 key购买 nike

以下摘录更改登录按钮的 html,直到从服务器收到响应。

在我的 iPhone 上测试使用 Cordova 构建的应用程序时。在更新登录按钮的 html 之前触发警报。在桌面浏览器中,它按预期工作。

我已经尝试将缓存和异步设置为 false,但没有任何区别。

除了不同的 ajax 库,我想不出还能尝试什么?

是否有更好的库可用于 Cordova 的 AJAX?

$.ajax({
data: $data,
cache: false,
async: false,
beforeSend: function() {
$('#btn-login').html('Logging In...');
},
success: function(r, status) {
if (r.status == 'success') {
getUser();
initNavSwipeGestures();
$('#page-index').removeClass('active');
} else {
alert(r.message);
}
},
error: function(data, status) {
alert(status);
}
});

最佳答案

成功时调用success - http://api.jquery.com/jquery.ajax/ :

success Type: Function( PlainObject data, String textStatus, jqXHR jqXHR ) A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.

如果您想检查返回的数据,请使用“success”……否则您应该使用“complete”。

像这样的东西应该可以工作:

$.ajax({
data: $data,
cache: false,
async: false,
beforeSend: function() {
$('#btn-login').html('Logging In...');
},
success: callback()
},
complete : function() {
getUser();
initNavSwipeGestures();
$('#page-index').removeClass('active');
},
error: function(data, status) {
alert(status);
}
});

var callback = function(response) {
///stuff to do after success here
};

关于javascript - jQuery Ajax 在 cordova iOS 应用程序上发送之前触发成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25264076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com