AJAX接不到传的值

来源:百度知道 编辑:UC知道 时间:2024/06/23 22:21:47
<head runat="server">
<title>RateTopic</title>

<body>
<form id="form1" runat="server">

<table width="178" bgcolor="#000000">
<tr>
<td width="150" align="left" nowrap="nowrap" style="cursor: crosshair;">
<img id="rate1" name="rate1" onmouseover="javascript:TurnImg('1');" onclick="javascript:SubmitRate('1');" src="images/green.gif"/>
<img id="rate2" name="rate2" onmouseover="javascript:TurnImg('2');" onclick="javascript:SubmitRate('2');" src="images/green.gif"/>
<img id="rate3" name="rate3" onmouseover="javascript:TurnImg('3');" onclick="javascript:SubmitRate('3');" src

function SubmitRate(score)
{
setXmlHttpRequest();
//异步请求
XmlHttp.onreadystatechange=states;
XmlHttp.open("GET","AddRate.aspx?score=" + escape(score),true);
XmlHttp.send();
}

这里写得有问题。

XmlHttp.open("GET","AddRate.aspx?score=" + escape(score),true);
这一句是请求。要写在上面。先请求才能给你回应吧。不然后怎么知道你要什么。

XmlHttp.onreadystatechange=states;
这句是回调方法。可以拿到请求的数据。

function SubmitRate(score)
{
setXmlHttpRequest();
XmlHttp.open("GET","AddRate.aspx?score=" + escape(score),true);
//异步请求
XmlHttp.onreadystatechange=states;

XmlHttp.send();
}