我正在尝试让AJAX在我的PhoneGap应用程序上运行。当使用PhoneGap Desktop服务器时,AJAX请求将到达PythonAnywhere服务器,如访问日志所示。
但是,将其转换为APK时,服务器未收到请求(在访问日志中看不到)。
HTML:https://pastebin.com/xG5MCf75
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Blank App</title>
</head>
<body>
<script type="text/javascript" src="cordova.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css"/>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
function testAjax(){
alert('button pressed')
$.ajax({
type: "POST",
headers:{'Access-Control-Allow-Origin':'*'},
url: "http://18choym.pythonanywhere.com/testAJAX",
data: {
someData: 'hi'
},
success: function(results){
alert('f1')
// console.log(results["data"])
// alert(results["data"])
alert('f2')
// acessing post data as 'result' returns an obj error.
},
error: function(error){
alert('Error Message: '+error)
}
})
}
</script>
<button onclick='testAjax();'>V3</button>
</body>
</html>