我嘗試了下面的代碼,通過單擊按鈕向jsp頁面發送請求。我檢查了Httpfox,但沒有要求。我只是在html代碼的主體中使用了整個代碼。我在做一些愚蠢的錯誤嗎?請建議..XMLHTTP請求請求不起作用
<button type="button" onClick="handleButtonClick();">Click Me!</button>
<script type="text/javascript">
function handleButtonClick()
{
// Declare the variables we'll be using
var xmlHttp, handleRequestStateChange;
// Define the function to be called when our AJAX request's state changes:
handleRequestStateChange = function()
{
// Check to see if this state change was "request complete", and
// there was no server error (404 Not Found, 500 Server Error, etc)
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var substring=xmlHttp.responseText;
// Do something with the text here
alert(substring);
}
}
xmlhttp = new XMLHttpRequest();
xmlHttp.open("GET", "http://csce:8080/test/index.jsp?id=c6c684d9cc99476a7e7e853d77540ceb", true);
xmlHttp.onreadystatechange = handleRequestStateChange;
xmlHttp.send(null);
}
</script>
好搭檔!完全錯過了,當我檢查它。這很可能是。 – 2010-10-18 04:28:03
謝謝我沒有意識到我正在使用不同的情況... – Judy 2010-10-18 04:49:32