gybmike 发表于 2013-1-29 10:32:54

一般ajax写法

function test(url, username, password, jQuery,callback) {    url = url || "/test.jsp";   jQuery.ajax({type:Get,   url: url,   async: true,   password:password,   username:username,   complete:function(xmlhttp, status){   var ok = (200 <= xmlhttp.status && xmlhttp.status < 300) || xmlhttp.status == 1223; // status 204 -> 1223 in IE   if (ok) {       callback(true);   } else {       callback(false);   }   }});    var xmlhttp;    if (window.XMLHttpRequest) {      xmlhttp = new XMLHttpRequest()    } else {      xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");    }    xmlhttp.onreadystatechange = function() {      if (xmlhttp.readyState == 4) {            var ok = (200 <= xmlhttp.status && xmlhttp.status < 300) || xmlhttp.status == 1223; // status 204 -> 1223 in IE            if (ok) {                callback(true);            } else {                callback(false);            }      }    };    xmlhttp.open("Get", url, true, username, password);    try {      xmlhttp.send(null);//error    } catch (e) {      callback(null);    }}
页: [1]
查看完整版本: 一般ajax写法