luozhaoyu 发表于 2013-1-23 01:19:48

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);   }
页: [1]
查看完整版本: Ajax小记