日期:2014-05-16  浏览次数:20766 次

一般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);
    }
}