一般ajax写法

匿名 (未验证) 提交于 2019-12-02 23:43:01
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);     } }

转载于:https://my.oschina.net/dddgggaaa/blog/204918

文章来源: https://blog.csdn.net/weixin_34250709/article/details/92046884
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!