Android emulator上令人困惑的jQuery/jsonp故障
我试图在andriod emulator上使用jsonp调用服务:Android emulator上令人困惑的jQuery/jsonp故障,android,jquery,jquery-mobile,android-emulator,Android,Jquery,Jquery Mobile,Android Emulator,我试图在andriod emulator上使用jsonp调用服务: bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, onDeviceReady: function() { app.receivedEvent('deviceready'); }, receivedEvent: f
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
receivedEvent: function(id) {
console.log('Received Event: ' + id);
$.ajaxSetup ({
cache: false
});
$.ajax({
type: "GET",
url: "http://10.0.2.2/uk-en/login/user",
dataType: "jsonp",
contentType: "application/json",
success: function(xml){
$("#result").html('123');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$("#result").html('XMLHttpRequest = ' + JSON.stringify(XMLHttpRequest) + ", textStatus = " + textStatus + ', errorThrown = ' + JSON.stringify(errorThrown));
}
});
}
我在HelloWorld应用程序上这样做,在phonegap网站上创建以下文档。我的index.html
与此类似:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<title>Hello World</title>
</head>
<body>
<div class="app">
<div id="result">
</div>
</div>
<script type="text/javascript" src="cordova-2.2.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
有人能帮忙吗?
JSONP
要求将响应封装在某种回调函数中
这都是假设您从另一个域获取内容。如果是这样,你也会受到同样的限制
因此,服务器应响应:
urFunction({....});
firefox中的响应被包装。这只发生在Android emulator应用程序中。我发现了问题。我的Android模拟器无法看到我的本地机器,尽管我认为我已经解决了这个问题。
urFunction({....});