无法获取AJAX响应,以将值传递给父Javascript脚本
下面的代码基于我在这里阅读的内容,但是显然,我缺少一些东西
//AJAX CALL, START
var response;
var ajax = new XMLHttpRequest();
var url = "hooks/__global_ajax_bespoke.php?address="+ address +"&club="+ club;
var method = "GET";
var asynchronous = true;
ajax.open(method, url, asynchronous);
//sending ajax request
ajax.send();
//receiving response from hooks/__global_ajax_bespoke.php
ajax.onreadystatechange =
function(){return(
function(){
if(this.readyState == 4 && this.status == 200){
response = this.responseText;
//alert (response+' TEST');
return response;
}
}
)}();
//AJAX CALL, END
//ACTING ON RETURNED RESPONSE, START
alert('SEE RESPONSE '+response);
if(response == "correct" || response == "incorrect"){
return show_error('club', 'Select a "Club" from within the same postcode as the address.');
}
else{
return show_error('club', 'ERROR FLAG FOR DEBUGGING PURPOSES.');
}
//ACTING ON RETURNED RESPONSE, END
好的地方-我知道我的回应是如预期的那样从php文件返回的 不好的地方-根据在该论坛和其他几个地方的了解,我期望通过返回anon函数,它将把其返回值传递给父javascript,但不会 任何帮助,请:) TIA