在过去的两天半里,我花在这个问题上的时间真的掉了头发…
使用phonegap构建iPhone和Android应用程序。跨域ajax工作在我的浏览器,也在iPhone上。它不能在Android上运行。
我一直没有使用jQueryMobile,只是jQuery,直到我读到某个地方,我应该使用移动版本得到跨域在android上工作。所以我改变了项目以适应jMobile。我真的需要使用JqueryMobile,以获得跨域ajax工作吗??如果可能的话,我宁愿不使用它。
尝试改变$.mobile.allowCrossDomainPages=true;.support美元。Cors = true;但无济于事。我很茫然。请帮帮我吧
这是我的ajax代码$.ajax({
url: 'URL',
type: 'GET',
contentType: "application/json",
dataType: 'jsonp',
jsonp: 'jsoncallback',
success: function(response){
console.log("inside ajax");
$.each(response, function(i,item){
var category = "<div class='icon-text'><a class='ajaxify' href='pages/onlineRecipe.html' onclick='$(setOnlineID("+item.id+"))' >"
+"<p><img alt='Image-alt' width='64' class='wrap-around' id='img"+item.id+"' />"
+"<strong>"+item.title+"</strong>"
+"<br/>"+item.desc+"</p></a></div>";
$('#categories').append(category);
var img = "#img" + item.id;
$(img).attr('src', "data:image/png;base64,"+item.image);
//other bindings
App.ajaxLinkify($("a.ajaxify"));
App.addTouchEvents($(".page"));
});
},
error: function(xhs, status, error){
//output.text('Ha producido un error cargando el dato. Por favor, intèntalo de nuevo.');
console.log("Ajax not working");
}
});
我的建议是检查<access origin="http://www.example.com" />
在res/xml/config.xml (cordova 2.3)
尝试添加jQuery.support.cors = true;
哦,还有一个技巧,以防它缓存之前的错误调用将它添加到ajax
cache: false,
需要添加到相应的php文件:header("Access-Control-Allow-Origin: *");