你好,
可能我没理解您意思。我们一般用onreadystatechange 事件是在Ajax异步刷新局部页面用的,向下面的代码,把反回来的数据填充到“txtHint” 里面:
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gethint.asp?q="+str,true);
xmlhttp.send();
}
但是,window.location.href用来请求一个新的页面的。如果还是不能工作,你可以尝试打个断点,debug一下,看看ajax发送请求没有,或者反回来的readyState and status是否正确。另外你可以考虑用jquery ajax,非常好用。详细信息你可以参考这里:
http://www.w3schools.com/jquery/jquery_ajax_get_post.asp
http://www.mikesdotnetting.com/Article/220/Posting-Data-With-jQuery-AJAX-In-ASP.NET-Razor-Web-Pages
Hope it can help you.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a
href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.