Cordova phonegap跨域获取未定义的值
这是我的问题。我使用jsonp来解决跨域问题,它在我的本地网页上工作(该网页请求远程服务器,而不是本地主机)。但当我将页面作为android应用程序部署到phonegap中时,错误返回为: XMLHttpRequest.status:200 XMLHttpRequest.readyState:4 text状态:parsererror XMLHttpRequest.responseText:未定义 以下是我的测试代码: 对于客户端:Cordova phonegap跨域获取未定义的值,cordova,cross-domain,jsonp,Cordova,Cross Domain,Jsonp,这是我的问题。我使用jsonp来解决跨域问题,它在我的本地网页上工作(该网页请求远程服务器,而不是本地主机)。但当我将页面作为android应用程序部署到phonegap中时,错误返回为: XMLHttpRequest.status:200 XMLHttpRequest.readyState:4 text状态:parsererror XMLHttpRequest.responseText:未定义 以下是我的测试代码: 对于客户端: $.ajax({ type: "GET",
$.ajax({
type: "GET",
async: false,
url:url,
dataType: "jsonp",
jsonp: "callback",
jsonpCallback:"myresult",
success: function(data){
if (data.flag == "success")
alert("yeah");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
alert(XMLHttpRequest.responseText);
}
});
对于服务器端,我使用php:
$callback = $_GET["callback"];
$a = array(
"flag"=>"success"
);
$result = json_encode($a);
echo "myresult($result)";
也许你应该知道你的域名。
白名单规则位于res/xml/config.xml(对于android)中,并用元素
声明使用数据类型:“json”
而不是jsonp
看这个例子
$.ajax({
type: "GET",
async: false,
url:url,
dataType: "json",
success: function(data){
if (data.flag == "success")
alert("yeah");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
另外,尝试
echo$result代码>而不是回显“myresult($result)”代码>我已经设置了白名单。我发现有一个错误:singleCursorHandlerTouchEvent-getEditableSupport FASLE当我按下submit按钮时,它与上面的问题有关吗?嗯,我没有遇到任何json问题。我已经做了一些jSON应用程序,所有的工作都很流畅。我不知道还有什么不对劲。若你们们愿意分享你们们的应用程序,那个么,也许有人能够发现问题。目前我没有主意了,抱歉,更多信息:如果我在HTML中设置url,如:和,我可以得到正确的响应。而如果我将url和白名单更改为www.mydomain.com,它将不起作用。PS:我的手机已连接到wifi。在成功:功能(数据)块中,我可以在没有数据的情况下提醒msg。标志==“成功”,但data.flag仍将错误报告为“Uncaught TypeError:无法读取null:555的属性“flag”