【JS】XMLHttpRequest使用笔记

时间:2020-03-19 19:38:01   收藏:0   阅读:54

 

            var xhr = new XMLHttpRequest();
       try { //加载中 Showloading(); } catch (err) { } xhr.open(‘POST‘, url); xhr.setRequestHeader("Content-type", "multipart/form-data"); xhr.responseType = ‘json‘; xhr.send(formData); xhr.onload = function (res) { console.log(‘done‘, res.target.response) $("#loadDIV").remove(); var result = res.target.response if (cusobj) { result.cusobj = cusobj } if (typeof (options.success) == ‘function‘) { options.success(result); } } xhr.onerror = function (res) { alert("上传失败"); } xhr.onloadend = function (res) { $("#loadDIV").remove(); }

 

 

function Showloading() {
    var div1 = ‘<div  id="loadDIV" class="layerbg"><div class="waitlayer"><div class="wtimg"><img src="/images/loading1.gif" width="32" height="32" /></div>‘;
    div1 += ‘<div class="wttxt">加载中...</div></div></div>‘;
    $(document.body).append(div1);
}

 

原文:https://www.cnblogs.com/laokchen/p/12526495.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!