-1
HTML-文書からXHRを実行します。私の文書に書き留め私は次のコードでHTMLで私のXHRをテストしようとした
<html>
<head>
<title> testing </title>
</head>
<body>
<div>
<script lang="JavaScript">
var clientID = "abc";
var secret = "def";
var oReq = new XMLHttpRequest();
oReq.withCredentials = true;
oReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
document.write("Going to make a call");
//OAuthAccessor.clientID, OAuthAccessor.secret
oReq.onreadystatechange = function() {
//console.log
document.write("state changed - new state: " + oReq.readyState + " and Status: " + oReq.status);
if (oReq.readyState === 4) {
if (oReq.status === 200) {
//console.log
document.write(oReq.responseText);
} else {
//console.log
document.write("Error: " + oReq.status + " Message: " + oReq.responseText);
}
}
};
//console.log
document.write("Status: " + oReq.status);
oReq.open("POST", "https://api.sandbox.paypal.com/v1/oauth2/token", true, clientID, secret);
oReq.send();
//console.log
document.write("Request send");
</script>
</div>
</body>
</html>
私はなっておりません何かを - そのコードが悪いのでしょうか?エミュレータから実行すると動作します。
あなたはlocalhostからしようとしていますか? – blewherself
のデバッグ101 - ブラウザ**の開発者**ツールコンソールを開いて、問題の原因を示す可能性のある警告/エラー/メッセージを確認します。 –
via file:/// path-to-file - 彼はその文書を見つけてそれを実行すべきです。 –