我已经启用了CORS,尝试了get和post方法,起初ajax调用工作正常但是现在它在浏览器中工作正常但是当我在我的设备上测试它进入错误函数我得到 误差=未定义 任何帮助将不胜感激
$("#createEvent_btn").click(function(e) {
//alert("in the function ");
if ($("#registerInfo").valid()) {
$(this).addClass('ui-disabled');
start = $("#startDate").val();
end = $("#endDate").val();
venue = $("#place").val();
var data2 = $("#registerInfo").serialize();
var params = data2;
alert(params);
//console.log(data2);
var url = 'http://domain/th/registerEvent.php';
//ajax.open("POST", url, true);
//ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// ajax.setRequestHeader("Content-length", params.length);
//ajax.setRequestHeader("Connection", "close");
var modurl = url + "?" + params;
alert(modurl);
ajax.open("GET", modurl, true);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200 || ajax.status == 0) {
//alert(ajax.response);
id = ajax.response;
alert(id);
$('#createEvent_btn').removeClass('ui-disabled');
setPeoplepage();
}
};
ajax.onerror = function(e) {
alert("Error ocurred. Error = " + e);
};
ajax.send(params);
}
});
答案 0 :(得分:0)
使用设备就绪功能
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
//your code here
}