【发布时间】:2016-02-02 15:24:54
【问题描述】:
我正在尝试发送 HTTP GET 请求,并且在我进行测试时一切正常。但是当我构建应用程序并尝试发送请求时,我收到 404 错误。
这是我的 index.html
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<access origin="*" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<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" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src http://google.com">
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>PhoneGap</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
var start = Date.now();
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
//alert(Date.now() - start);
alert("yeah");
}
else if(xmlhttp.status == 400) {
alert('There was an error 400');
}
else {
alert("else: " + xmlhttp.status);
}
}
}
xmlhttp.open("GET", "http://google.com", true);
xmlhttp.send();
</script>
</body>
我是 PhoneGap 的新手,我确信这很简单,但我在 google 上找不到任何东西。
提前致谢
【问题讨论】:
-
http://myserver/ping是一个有效的网址吗?你确定那里没有.com或端口号之类的东西吗? -
是的,它是一个开放的 api,所以我不想发布真正的 url