【发布时间】:2019-05-21 05:27:23
【问题描述】:
使用 Cordova 8.0.0、iOS 12.1.2,尝试向我的服务器发出 GET 请求。
我可以成功地向服务器发出请求,但是如果由于某种原因需要超过 10 秒的时间,那么它就会失败。如果花费的时间少于此,它确实有效。
这仅发生在 iOS 中,应用的 Android 版本不显示此行为,并遵守我在下面设置的超时。
示例 sn-p:
$.ajax({
type: "GET",
url: actionUrl,
data: data,
cache: false,
dataType: "xml",
timeout: 300000,
async: false,
beforeSend: function (request) {
request.setRequestHeader("user", settings.userId);
request.setRequestHeader("sid", settings.sessionKey);
},
success: function (results) {
callback(results);
},
error: function (e) {
if (!surpressError){
main.ajaxError(e);
}
main.stopLoading();
if (errorCallback){
errorCallback(e);
}
}
});
如果我创建 async: true 或只是删除那部分,请求可能需要超过 10 秒才能完成,但使用这个旧版应用程序,我宁愿不必更改更多内容,而不必适应转变。
我还尝试将 <preference name="loadUrlTimeoutValue" value="300000" /> 添加到我的 config.xml 中,超时时间不到 1 分钟 (30000),但这没有帮助。
还有其他方法可以确保我错过的超时时间超过 10 秒吗?
【问题讨论】:
-
永远不要使用
async:false。这是一种可怕的做法,已被弃用。您应该会在浏览器开发工具控制台中看到有关弃用的警告。对于长请求尤其不利
标签: javascript jquery ios ajax cordova