0
ボタンをクリックすると、soapRequest is not defined
エラーが発生します。soapRequestが定義されていません
このエラーを修正するにはどうすればよいですか?
マイコード:
<head>
<script type="text/javascript">
var soapRequest = function() {
var str = //the soap request code
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, false);
} else if (typeof XDomainRequest != "undefined") {
alert xhr = new XDomainRequest();
xhr.open(method, url);
} else {
console.log("CORS not supported");
alert("CORS not supported");
xhr = null;
}
return xhr;
} //end of function createCORSRequest//
//calling the xhr
var xhr = createCORSRequest("POST",
"https://thelocalserver/therequest?wsdl");
if (!xhr) {
console.log("XHR issue");
return;
}
xhr.onload = function() {
var results = xhr.responseText;
console.log(results);
} //end of function onload
xhr.setRequestHeader('Content-Type', 'text/xml');
xhr.send(str);
} //end of function soapRequest//
</script>
</head>
<body>
<form name="Demo" action="" method="post">
<div>
<input type="button" id="API" value="Soap" onClick="soapRequest" />
</div>
</form>
</body>
<html>
ので、どの行でエラー? – nmnsud
あなたの問題だが、 'alert xhr = new XDomainRequest();'は意味をなさない。 –
'var str = function createCORSRequest(method、url){' ... '}'のように関数を定義している場合は、 'str(' ... ')'として呼び出す必要があります。 'createCORSRequest(' ... ')'として呼び出すことはできません。 'str ='行は異なる値を保持するように見えますが。 [JSHint](http://jshint.com/)を使用して、すぐにコードの問題を見つけてください。 – Xufox