var xmlHttp; function createXMLHttpRequest() { if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } else { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } } function createQueryString() { return "name=" + document.getElementById("name").value; } function startRequest() //页面调用的JavaScript函数 { var url = "http://127.0.0.1/Ajax/TestAjax?timeStamp=" + new Date().getTime(); //强制刷新 createXMLHttpRequest(); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.open("POST", url); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlHttp.send(createQueryString()); } function handleStateChange() { if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { document.getElementById("response").innerHTML = xmlHttp.responseText; } } }
JavaScript调用Ajax
最新推荐文章于 2024-04-09 21:30:56 发布