我正在用PhoneGap 2.5編寫我的第一個Android應用程序;該應用程序非常簡單,只需讀取本地gps座標並將其發送到遠程服務器以及一些設備數據(uuid,android版本)和一些輸入字段。 當應用程序啓動時,它向遠程服務器發送一種「設備註冊」,並接收一些數據Android 2.3.x上的jQuery發佈錯誤(致力於Android v4.x)
截至目前,我只使用jquery v1.9.1,沒有jquery mobile或其他javascript庫。
下面的代碼
onDeviceReady: function() {
$.support.cors = true;
app.deviceRegister();
// navigator.splashscreen.hide();
},
deviceRegister: function() {
var params = {
'device_uuid': window.device.uuid,
'device_platform': window.device.platform,
'device_model': window.device.model,
'device_version': window.device.version,
};
var url = app.data.url + 'devices/register'; // app.data.url defined elsewhere
$.ajax(url, {
type: "POST",
data: params,
timeout: 5000,
success: function(response) {
// updates html with received data
$("#user_badge").html(response.badge);
$("#user_name").html(response.full_name);
},
error: function(x, t, m) {
if (t === 'timeout') {
navigator.notification.alert('timeout error');
} else {
navigator.notification.alert('error: ' + t);
}
},
dataType: 'json'
});
},
當施加到的Android 4.x版(包括仿真器和實際裝置)它完美,數據被髮送到遠程服務器,並響應被正確地管理。
的問題是,如果我運行在Android v2.3.x(包括模擬器和真實設備)的應用程序:沒有數據發送和所有我得到的是一個警告「錯誤:錯誤」。
我以爲有什麼東西的Android 2.3和jQuery 1.9之間撥錯,但我只是不能得到問題的所在。
任何猜測?
嘗試檢查此線程上的解決方案http://stackoverflow.com/questions/11434930/jquery-ajax-fails-on-android-tablet-browser – wmfairuz
我試圖給$添加一個「async:false」。阿賈克斯選項,但沒有奏效。 我也試過jQuery的老版本(1.6.4,1.7.2,1.8.3)沒有成功。 任何其他猜測? –
您是否更改了config.xml中的訪問原始參數? – QuickFix