Use ajax to click on different links on a web page, and then display the returned results in the fixed p of the page
/* The following code uses ajax to click on different links on a web page, The returned results are then displayed in the fixed p on the page. */
<html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <script language="javascript"> var http_request = false; function createRequest(url,objID){ http_request = false; if(window.XMLHttpRequest){ //非IE浏览器 http_request = new XMLHttpRequest(); if(http_request.overrideMimeType){ http_request.overrideMimeType("text/xml"); } }else if(window.ActiveXObject){ //IE浏览器 try{ http_request = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ http_request = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){} } } if(!http_request){ alert("无法创建XMLHTTP实例"); return false; } http_request.open("GET",url,true); http_request.send(null); var obj = document.getElementById(objID); http_request.onreadystatechange = function(){ if(http_request.readyState == 4){ if(http_request.status == 200){ obj.innerHTML = http_request.responseText; }else{ alert('您请求的页面发现错误!'); } } } } </script> </head> <body onload="createRequest('content1.html','show')"> <p align="center"> <a href="content1.html" onclick="createRequest('content1.html','show');return false;">no1</a> | <a href="content2.html" onclick="createRequest('content2.html','show');return false;">no2</a> | <a href="content3.html" onclick="createRequest('content3.html','show');return false;">no3</a> </p> <p id="show" align="center"></p> </body> </html>
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Ajax verification user name and password example code
Ajax implementation code for passing multiple parameters
laypage front-end paging plug-in implements ajax asynchronous paging
##
The above is the detailed content of Ajax implements clicking different links to display the returned content in a specific div. For more information, please follow other related articles on the PHP Chinese website!