Jud*_*udy 2 javascript ajax jsp xmlhttprequest
我尝试了以下代码,只需点击一下按钮就可以向jsp页面发送请求.我检查了Httpfox,但没有请求.我只是在html代码的主体中使用了整个代码.我做了一些愚蠢的错误.请建议..
<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>
Run Code Online (Sandbox Code Playgroud)
好吧,在JavaScript中,变量区分大小写.你有xmlHttp和xmlhttp; 那些应该是一样的.
您还遇到了块<pre><code>的开头<script>,这是一个JavaScript语法错误.