ajax 长链接,能够同时send图文,稳定性没有websocket好

 function uploadSendTextAll(link,content,name) {
                var count = "";
                var id_start = $("#id_start").val();
                var id_end = $("#id_end").val();
                $.post('/manage/iframe/member/GetMemberCount?id_start='+id_start+'&id_end='+id_end, function(data){
                     count = data;
                     var t = document.getElementById("loadpicS");
                     var f = document.getElementById("loadpicF");
                     t.innerHTML = "loading...";
                     var xhr = createXHR(); 
                     var oldSize=0;
                     var success="0";
                     var successP="";
                     var fail = "0";
                     var failP="";
                     xhr.onreadystatechange = function(){
                         if(xhr.readyState == 3||xhr.readyState == 4){
                             var result = xhr.responseText.substring(oldSize);
                             oldSize = xhr.responseText.length;
                             var obj = eval("(" + result + ")");
                             var failP = obj.failP;
                             var successP = obj.successP;
                             if (typeof(failP)!="undefined") {
                                   f.innerHTML ="失败:"+ failP + "/"+count;
                                   fail=failP;
                               }else {
                                   f.innerHTML ="失败:"+ fail + "/"+count;
                               }
                             if (typeof(successP)!= "undefined") {
                                   t.innerHTML ="成功:"+ successP + "/"+count;
                                   success=successP;
                               }else {
                                   t.innerHTML = "成功:"+success + "/"+count;
                               }    
                         }
                         if(xhr.readyState == 4){            
                             // 请求执行完毕
                             f.innerHTML = "";
                             t.innerHTML = "总计"+count+"条,成功"+ success+"条,失败"+fail+"条";return;
                         }
                     }
                     xhr.open('post','/manage/iframe/member/KfSendAll2?name='+name+'&link='+link+'&content='+content+'&id_start='+id_start+'&id_end='+id_end);
                     var uploadfile = document.getElementById("uploadfile").files[0]; // js 获取文件对象
                     var form = new FormData(); // FormData 对象
                     form.append("uploadfile", uploadfile); // 文件对象
                     xhr.send(form);
                })
            }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值