【发布时间】:2014-01-16 02:10:15
【问题描述】:
我正在使用 PhoneGap 2.5 编写我的第一个 Android 应用程序;该应用程序非常简单,只需读取本地 gps 坐标并将它们连同一些设备数据(uuid、android 版本)和一些输入字段一起发送到远程服务器。 当应用程序启动时,它会向远程服务器发送一种“设备注册”并接收一些数据
到目前为止,我只使用 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 v4.x(模拟器和真实设备)时,它可以完美运行,数据被发送到远程服务器并正确管理响应。
问题是,如果我在 Android v2.3.x(模拟器和真实设备)上运行应用程序:没有数据发送,我得到的只是“错误:错误”的警报。
我认为 android 2.3 和 jquery 1.9 之间存在一些问题,但我就是不知道问题出在哪里。
你猜到了吗?
【问题讨论】:
-
尝试在这个线程stackoverflow.com/questions/11434930/…查看解决方案
-
我尝试在 $.ajax 选项中添加“async: false”,但没有成功。我还尝试了较旧的 jquery 版本(1.6.4、1.7.2、1.8.3),但没有成功。还有其他猜测吗?
-
你修改了config.xml中的访问源参数吗?
标签: javascript android jquery cordova