在我的代碼中responseText不起作用。它應該顯示,文本在文本框中+進入「:您的申請已經看到由SYAM」responseText - XMLHttpRequest
<html>
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
var xmlHttpRequest;
function sSignature(str) {
xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.onreadystatechange = function() {
if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
document.getElementById("target").innerHTML = xmlHttpRequest.responseText;
}
}
xmlHttpRequest.open("GET", "AjaxResponse.aspx?q=" + str, true);
xmlHttpRequest.send();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
enter a string :<input type="text" id="textbox" onkeyup="sSignature(this.value)"/>
<span id="target">text should change here</span>
</div>
</form>
</body>
</html>
在代碼隱藏頁中的Page_Load()
string sRequest = Request.QueryString["q"];
var sResponse = sRequest+ " :Your request has been seen by syam";
Response.Write(sResponse);
你可以做得比「不工作」更好?網絡流量檢查員說什麼?控制檯中是否有錯誤?你有沒有試圖看看它在錯誤出現之前在代碼中有多遠? – Amadan 2012-01-03 08:50:27
當readystate爲4時,它在行中發生錯誤document.getElementById(「target」)。innerHTML = xmlHttpRequest.responseText; – dotnetrocks 2012-01-03 09:03:48
...哪個錯誤? – Amadan 2012-01-03 09:04:56