js什么情况下会出现阻塞?
高洛峰
高洛峰 2016-10-27 11:01:31
0
1
642

1、警告信息:Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
2、代码
//添加按妞事件
function addClick(obj){

//判断右侧列表是否已包含该商品
var myid = $(obj).parent().parent().attr("data-id");
var theGoods = $("#tailList").find("tr[data-id='"+myid+"']");
var _th=$(obj).parent().parent();
var datanum =  _th.attr('data-id');
var price = parseFloat($("#price_"+datanum).val());
var vipprice = parseFloat($("#vipprice_"+datanum).val());
if(theGoods.length>0){
    var theGoodsAmount = $($(theGoods).find(".ct_nnm")[0]).html();
    $(obj).parent().parent().find(".ct_nnum").html(parseInt(theGoodsAmount)).removeClass("disnone");
    adds2($(obj).parent().find(".readd").children().first(),"price_"+datanum);
    $(obj).addClass("disnone");
    return ;
}
//校验数量
var num = parseInt($(obj).parent().parent().find(".ct_nnum").text());
var canuseamount = $("td[data-name='canuseamount']",$(obj).parent().parent()).text();//可售数量
var cansale=0;
var consumerlinkstock = $("#consumerlinkstock").val();
if(consumerlinkstock=="0"){//关联库存,不能超过库存数量
    cansale = parseInt(canuseamount);
    if(cansale<1){
        var msg="<s:text name='salegoods.merchandise_sales.consumpationdetails.storenotenough' ><s:param>"+canuseamount+"</s:param></s:text>";
        alert(msg,function(){},"warning",false);
        return;
    }
}else{//未关联库存,默认上限为999
    if(num>=999){
        alert("<s:text name='salegoods.merchandise_sales.consumpationdetails.buynumoverflow' />",function(){},"warning",false);
        return;
    }
}

//更新到“购物车”
$.ajax({
    url:"consumerCart.html?goodsno="+$(_th).attr("data-id")+"&amount=1"+"&price="+price,

// data:{"cartgoods.price":price,"cartgoods.totalprice":totalprice,"cartgoods.title":title,"cartgoods.bid":"","cartgoods.goodsid":goodsid,"cartgoods.gsn":gsn,"cartgoods.tid":tid,"cartgoods.direct":direct,"cartgoods.validity":validity},

    type:"POST",
    dataType:"text",
    async:false,
    success:function(){},
    error:function(){return false;}
});

//页面操作
var myrownum = $(".mydetail").length;
var str="<tr data-id='"+_th.attr('data-id')+"' class='mydetail'>"+
            "<td>"+$('.good-name',_th).text()+"</td>"+
            "<td class='ct_sp'>"+price+"</td>"+
            "<td class='vct_sp'>"+vipprice+"</td>"+
            "<td><img src='inc/images/reduce.png' onclick='reduce(this)' class='v_m' /> <span class='ct_nnm'  >1</span> <img src='inc/images/add.png' onclick='adds(this)' class='v_m' /></td>"+
            "<td class='ct_tot' >"+price+"</td>"+
            "<td class='vct_tot' >"+vipprice+"</td>"+
            "<td style='display:none;'>"+
                '<input type="hidden" name="mygoodsli['+myrownum+'].price" value="'+price+'" data-name="myprice"/>' +
                '<input type="hidden" value="'+vipprice+'" data-name="vipmyprice"/>' +
                '<input type="hidden" name="mygoodsli['+myrownum+'].count" value="1" data-name="mycount" />' +
                '<input type="hidden" name="mygoodsli['+myrownum+'].totalprice" value="'+price+'" data-name="mytotalprice" />' +
                '<input type="hidden" value="'+vipprice+'" data-name="vipmytotalprice" />' +
                '<input type="hidden" name="mygoodsli['+myrownum+'].bid" value="" />' +
                '<input type="hidden" name="mygoodsli['+myrownum+'].title" value="'+$("[data-name='title']",$(_th)).html()+'" />' +
                '<input type="hidden" name="mygoodsli['+myrownum+'].goodsid" value="'+$("[data-name='goodsid']",$(_th)).html()+'" />' +
                '<input type="hidden" name="mygoodsli['+myrownum+'].gsn" value="'+$("[data-name='gsn']",$(_th)).html()+'" />' +
                '<input type="hidden" name="mygoodsli['+myrownum+'].tid" value="'+$("[data-name='tid']",$(_th)).html()+'" />' +
                '<input type="hidden" name="mygoodsli['+myrownum+'].direct" value="'+$("[data-name='direct']",$(_th)).html()+'" />' +
                '<input type="hidden" name="mygoodsli['+myrownum+'].validity" value="'+$("[data-name='validity']",$(_th)).html()+'" />' +
            "</td>"+
        "</tr>";

$('.ct_tblst').append(str);
_th.find('.ct_nnum').removeClass('disnone');
$(obj).addClass('disnone');
consume();


高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回覆(1)
三叔

$.ajax中把async:false改为async:true,请使用异步的方式发送请求

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!