문제 : Chrome에서 작업하는 동안 스크립트는 동기식 xhr 응답을 기다리지 않습니다. FireFox/IE에서 잘 작동합니다. onreadyStateHandlers도 사용했지만 응답을 받기 전에 다른 코드가 실행됩니다.Chrome에서 XHR 동기화 호출에 실패했습니다. xhr 응답을 기다리지 않는 스크립트
function callingScript()
{ var a=callServer();
alert(a);//Here a is showing undefined while executing in chrome.
But in FF/IE its waiting for the response and then alerts a with response.
}
function callServer()
{
var response;
var httpRequest = new XMLHttpRequest();
httpRequest.open("POST","abc",false);
httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState != 4)
{return; }
if (httpRequest.status != 200)
{response=httpRequest.status;}
else {response=httpRequest.responseText;}
};
httpRequest.send(data);
return response;
}
의견을 남겨주세요 !!
귀하의 문제는 긴급하다는 말은 답변을 얻는 데 도움이되지 않으며 실제로 사람들을 도와 줄 수는 없습니다. –