JS 함수를 호출 할 때 게시 요청을 보내려고합니다. 브라우저에서 나는 보낼 것이다 :Javascript serialized POST
http://myuser:[email protected]:80/api/callAction?deviceID=185&name=turnOn
이 작동합니다. 아직 내 코드에서는 그렇지 않습니다.
참고 사항 : - Chrome에서 오류가 발생합니다. 요청이 액세스 제어를 통과하지 못합니다. Chrome에서이 기능을 사용 중지하면이 오류가 표시되지 않지만 아직 서버의 응답이 표시되지 않습니다.
<script type="text/javascript">
function changestate() {
var http = new XMLHttpRequest();
http.withCredentials = true;
var user = "bassie"
var pass = "password"
var url = "http://hc2/api/callAction";
var params = "deviceID=185&name=turnOff";
http.open("POST", url, true);
http.setRequestHeader("Authorization", "Basic " + user + ":" + pass);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
alert(http.responseText);
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
}
</script>
이'가 자바 스크립트와 웹 페이지를 포함하는 서버의 이름을 hc2'이다 : 그것의 요점 아래? – Barmar
문제를 조사해 주셔서 감사합니다. HC2는 사후 요청 (대상 서버)을 가져 오는 서버의 이름입니다. – Bassie
요청을 보내는 서버의 이름이 아니라면 도메인 간 AJAX를 실행하고있는 것입니다. – Barmar