ajax: http_request
<script type="text/javascript">
function ajax(){
xmlhttp_request = getXmlrequest();
xmlhttp_request.open("get", 'http://127.0.0.1/testan/test', true);
xmlhttp_request.onreadystatechange = ajaxlistner;
xmlhttp_request.send(null);
}
function ajaxlistner(){
if (xmlhttp_request.readyState == 4) {
// 收到完整的服务器响应
if(xmlhttp_request.status==200){
var text = xmlhttp_request.responseText;
document.getElementById("div_id").innerHTML=text;
}
}
}
function getXmlrequest(){
var http_request;
if(window.XMLHttpRequest){//Mozilla浏览器
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){//设置MIME类型
http_request.overrideMimeType("text/html");
}
}
else if(window.ActiveXObject){//IE浏览器
try{
http_request=new ActiveXObject("Xsxml2.XMLHTTP");
http_request.setRequestHeader("Content-Type","text/xml");
http_request.setRequestHeader("Content-Type","utf-8");
}catch(e){
try{
http_request=new ActiveXObject("Microsoft.XMLHTTP");
http_request.setRequestHeader("Content-Type","text/xml");
http_request.setRequestHeader("Content-Type","utf-8");
}catch(e){
}
}
}
return http_request;
}
</script>
<body>
This is my JSP page. <br>
<input type="text" οnblur="ajax()"/>
<div id="div_id"></div>
</body>
服务器端代码,不要有转页,用response的输出流输出内容。