我有一个用 HTML5、Javascript、css3 编写的应用程序,使用 PhoneGap 为 iOS 和 Android 编译。它收集调查信息并通过 Ajax 调用将其上传到在线主机。它一直运行良好,直到最近上传代码似乎停止工作。不完全!在 iPad 上,它说成功,但实际上没有任何东西可以到达主机。这很奇怪。我已经尝试根据此处的文章重写 Ajax 调用,但没有运气。
iOS - 6.1.3、PhoneGAP 2.7.0、PhoneGap/Adobe Build 使用。
这是上传片段...
function sendToWeb(){
var errorflag = false;
db.transaction(function (tx) {
tx.executeSql("SELECT weburl FROM settings", [], function(tx, results){
var webURL = results.rows.item(0).weburl;
tx.executeSql("SELECT * FROM surveypretransfer WHERE uploaded = '0'",[], function(tx, results){
if (results.rows.length == 0) {
alert("You have no surveys waiting to upload");
} else {
alert("You have " + results.rows.length + " surveys waiting to upload");
for (var i=0; i < results.rows.length; i++) {
var responseURL = webURL + "/feeds/saveinfo.php";
var responseString = results.rows.item(i).responsestring;
var localid = results.rows.item(i).id;
//alert(localid);
$.ajax({
type: 'POST',
data: responseString,
url: responseURL,
timeout: 30000,
success: function(data) {
alert('Success!' + data.join('\n'));
},
error: function(data) {
alert(data.join('\n'));
console.log("Results: " + localid);
alert("Error during Upload. Error is: "+ data.statusText);
}
}); //ajax
}; //for loop
alert("You have successfully uploaded "+ results.rows.length + " survey results");
tx.executeSql("UPDATE surveypretransfer SET uploaded = '1' WHERE uploaded = '0'");
}; //if statement
}); //tx.execute
});
}, errorCB);
}
在 iPad 上加载时,这两个警报都不会触发。在 Android 上运行良好,之前在 iPad 上运行过,所以我找不到发生了什么变化。
更新:似乎这仅适用于仅 WiFi 的 iPad。我测试的所有3G都很好。算了!
Config.XML contains app id = "com.mydomain.myapp" (as an example)
URL for upload is "http://customer.mydomain.com/feeds/saveinfo.php?..."
Also added line 'access origin="http://mydomain.com" subdomains="true" '
仍然没有结果。有没有人看到/有类似的问题?有人看到我的错误吗?