<script type="text/javascript">
function ajax() {
//先聲明一個(gè)異步請(qǐng)求對(duì)象
var xmlHttpReg = null;
if (window.ActiveXObject) {//如果是IE
xmlHttpReg = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
xmlHttpReg = new XMLHttpRequest(); //實(shí)例化一個(gè)xmlHttpReg
}
//如果實(shí)例化成功,就調(diào)用open()方法,就開(kāi)始準(zhǔn)備向服務(wù)器發(fā)送請(qǐng)求
if (xmlHttpReg != null) {
xmlHttpReg.open("get", "chuli.php?uid="+uid+"&pwd="+pwd, true);
xmlHttpReg.send(null);
xmlHttpReg.onreadystatechange = doResult(); //設(shè)置回調(diào)函數(shù)
}
//回調(diào)函數(shù)
//一旦readyState的值改變,將會(huì)調(diào)用這個(gè)函數(shù),readyState=4表示完成相應(yīng)
//設(shè)定函數(shù)doResult()
function doResult() {
if (xmlHttpReg.readyState == 4) {//4代表執(zhí)行完成