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
IDK라면 문제는 아니지만'alert xhr = new XDomainRequest(); '는 의미가 없습니다. –
'var str = function createCORSRequest (method, url) {'...'}'와 같이 함수를 정의한다면,'str ('...')'이라고 부를 필요가 있습니다. 'createCORSRequest ('...')'로 호출 할 수 없습니다. 'str ='행은 다른 값을 유지해야하는 것처럼 보입니다. [JSHint] (http://jshint.com/)를 사용하여 코드의 문제점을 즉시 찾으십시오. – Xufox