私はアプリケーションサーバーにGETリクエストを介してフォームを送信しようとしています。しかし私はそれが不可能であることを発見しています。私は白いリストのプラグインがインストールされていることを確認して保証しました、そして、私のconfig.xmlを以下に含めました。私はまた、許可的なコンテンツセキュリティポリシーを設定しました。フォームAndroidでCordova Async XMLHttpRequest()。openが動作しない
document.getElementById("submit-feed").addEventListener("click", function() {
alert('Request Sent!');
var feed_url = document.getElementById('url').value;
var gcm_id = window.localStorage.getItem("gcm_id");
var url = "http://app-server-1.cloudapp.net/schedule/"+encodeURIComponent(feed_url)+"/"+gcm_id;
log("<b>Url:</b> "+url);
log("Before request block");
var request = new XMLHttpRequest();
log("Before opening request");
alert(request.open("GET", url, true));
log("After opening request]");
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200 || request.status == 0) {
alert(request.responseText);
} else {
alert("didn't work")
}
}
log('Reached onreadystatechange');
};
log("After onreadystatechange block");
log('Before GET request');
request.send();
log('After GET request');
function log(message) {
document.getElementById("messages").innerHTML = message;
}
});
01を提出する
コンテンツセキュリティポリシー
<meta http-equiv="Content-Security-Policy" content="default-src 'self' app-server-1.cloudapp.net data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
config.xmlの
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.notifyme" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>notifyme</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="[email protected]" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="http://app-server-1.cloudapp.net/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<engine name="android" spec="~6.0.0" />
</widget>
HTMLフォーム
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' gcm-android-1.cloudapp.net data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<title>notifyme</title>
</head>
<body>
<h1>notifyme</h1>
Our clairvoyant service will notify you when things happen <br/>
<p id="messages"></p>
<p id="gcm_id"></p>
Name of Feed:<br>
<input type="text" name="name" id="name">
<br>
Url of Feed:<br>
<input type="text" name="url" id="url">
<br><br>
<button id="submit-feed">Notify me</button>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
のJavascript
フォームを送信すると、コードが実行されるのは Before opening request
私は警告なしで試しましたが、依然としてrequest.open( "GET"、url、true)の呼び出しを取得できませんでした。この後に何も実行されません。 – Jonathan
console.log – Harminder