在过去的两天半时间里,我在这个问题上掉了头发……
使用phonegap构建适用于iPhone和安卓的应用程序。跨域ajax可以在我的浏览器中运行,也可以在iPhone上运行。它不会在Android上工作。
我一直没有使用jQueryMobile,只是使用jQuery,直到我在某个地方读到我应该使用移动版本来获得跨域在安卓上的工作。因此,我更改了项目以适应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");
}
});发布于 2014-08-07 16:44:38
需要添加到对应的php文件: header("Access-Control-Allow-Origin:*");
发布于 2013-01-14 22:15:54
我的建议是在res/xml/config.xml (Cordov2.3)中检查<access origin="http://www.example.com" />
发布于 2013-01-14 22:38:43
尝试添加此jQuery.support.cors = true;
哦,还有另一个技巧,只是为了防止缓存之前的错误调用,将以下代码添加到ajax中
cache: false,https://stackoverflow.com/questions/14319624
复制相似问题