Ajax初记

Ajax小记使用Ajax的简单函数var xmlhttpfunction useAjax(url, func, data) {if (window.XMLHttpRequest)

Ajax小记
使用Ajax的简单函数

var xmlhttp;   function useAjax(url, func, data) {              if (window.XMLHttpRequest) {           xmlhttp = new XMLHttpRequest();       } else {           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");       }        xmlhttp.onreadystatechange = func;    xmlhttp.open("POST", url, true);        //Send the proper header information along with the requestxmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");xmlhttp.setRequestHeader("Content-length", data.length);xmlhttp.setRequestHeader("Connection", "close");    xmlhttp.send(data);}     function asynVisit(url) {var data = "name=smith&sex=male";    useAjax(url, function() {           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {               alert(xmlhttp.responseText);           }       }, data);   }