首页 新闻 赞助 找找看

Ajax 请求次数过多,请求就卡死了【状态变成pending】,怎么解决,

0
悬赏园豆:200 [已解决问题] 解决于 2018-06-06 13:38

后台方法:

  #region 入库扫描
        /// <summary>
        /// 入库扫描
        /// </summary>
        /// <param name="productSN">产品序列号</param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetInstock(string productSN, string lotSN, int planQty,string radomTime)
        {
            //1.先判断SN是否重复
            if (!string.IsNullOrEmpty(productSN))
            {
                bool resultSN = bll.IsExistsSN(productSN);
                int scanQty = 0;
                if (resultSN)
                {
                    //验证计划入库数量和已扫描的数量
                    DataTable dt = bll.OverInStockQty(lotSN);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        int planCount = Convert.ToInt32(dt.Rows[0]["F_Qty"]); /*计划入库数量*/
                        scanQty = Convert.ToInt32(dt.Rows[0]["F_SNIndex"]);/*已扫描数量*/
                        if (scanQty >= planCount)
                        {
                            //已扫描的数量,大于计划入库数量
                            return Json("OverStockQty", JsonRequestBehavior.AllowGet);
                        }
                        else
                        {
                            Dictionary<string, int> lstStrSN = new Dictionary<string, int>();
                            InStockModel insertModel = new InStockModel()
                            {
                                F_UserID = CookieHelper.GetCookieValue("hcUserName"), //Session["UserName"].ToString(),
                                F_LotSN = lotSN,
                                F_SN = productSN,
                                F_PCName = Environment.MachineName,
                                F_Qty = planQty
                            };
                            int result = bll.InsertInstock(insertModel);
                            if (result > 0)
                            {
                                //更新已入库数据
                                bll.UpdateScanQty(result);
                                scanQty += 1;
                                lstStrSN.Add(productSN, scanQty);
                                return Json(new JavaScriptSerializer().Serialize(lstStrSN), JsonRequestBehavior.AllowGet);
                            }
                        }
                    }
                    if (dt!=null&& dt.Rows.Count == 0)
                    {
                        Dictionary<string, int> lstStrSN = new Dictionary<string, int>();
                        InStockModel insertModel = new InStockModel()
                        {
                            F_UserID = CookieHelper.GetCookieValue("hcUserName"), //Session["UserName"].ToString(),
                            F_LotSN = lotSN,
                            F_SN = productSN,
                            F_PCName = Environment.MachineName,
                            F_Qty = planQty
                        };
                        int result = bll.InsertInstock(insertModel);
                        if (result > 0)
                        {
                            //更新已入库数据
                            bll.UpdateScanQty(result);
                            scanQty = 1; 
                            lstStrSN.Add(productSN, scanQty);
                            return Json(new JavaScriptSerializer().Serialize(lstStrSN), JsonRequestBehavior.AllowGet);
                        }
                    }
                }
                else
                {
                    //重复序列号
                    return Json("RepeatSN", JsonRequestBehavior.AllowGet);
                }
            }
            else 
            {
                //请输入序列号
                return Json("EmptySN", JsonRequestBehavior.AllowGet);
            }
            //出现错误
            return Json("Error", JsonRequestBehavior.AllowGet);
        }
        #endregion

前台代码:

 $('#txtProductSN').textbox({
            inputEvents:$.extend({},$.fn.textbox.defaults.inputEvents,{
            keyup:function(event){ 
                if(event.keyCode == 13) {
                    var sn=$.trim($("#txtProductSN").textbox("getValue"));  /*产品序列号*/
                    var num = $.trim($("#lotSNNumber").textbox('getValue'));  /*计划扫描数量*/
                    var lotSN = $.trim($("#lotSN").textbox('getValue'));
                    if(sn==null||sn==""||typeof(sn)=="undefined"){
                        $.messager.alert('温馨提示', "请输入产品序列号!", 'warning');
                        $("#txtProductSN").textbox('textbox').focus();
                        return false;
                    }
                    if(sn.length>16){
                        $.messager.alert('温馨提示', "产品序列号长度超过16位数,请检查是否输入正确!", 'warning');
                        $("#txtProductSN").textbox('textbox').focus();
                        return false;
                    }
                    else{
                        $.when(Js_Instock.GetInstocking(sn,lotSN,num).done(function(dataResult){
                              /*没有输入序列号*/
                           if(dataResult=="EmptySN"){
                                $.messager.alert('温馨提示', "请输入产品序列号!", 'warning');
                                $("#txtProductSN").textbox('textbox').focus();
                                return false;
                            }
                            /*重复序列号*/
                            if(dataResult=="RepeatSN"){
                                $.messager.alert('温馨提示', "相同的产品序列号:【"+sn+"】已入库一次,不能重复入库!", 'warning');
                                //$("#lblRepeatSN").append(sn+"<br/>");
                                return false;
                            }
                            /*已扫描数量大于计划入库数量*/
                            if(dataResult=="OverStockQty"){
                                $.messager.alert('温馨提示', "已经扫描入库的数量不能大于计划入库的数量!", 'warning');
                                return false;
                            }
                            /*系统错误,请联系管理员!*/
                            if(dataResult=="Error"){
                                $.messager.alert('温馨提示', "入库失败!!!", 'warning');
                                return false;
                            }
                            else{
                                $('#lotSNList').datalist('appendRow',{text:dataResult.substring(2,dataResult.indexOf(':')-1),value:dataResult.substring(2,dataResult.indexOf(':')-1)});
                                $("#txtProductSN").textbox('clear');
                                $("#lblScanCount").text(dataResult.substring(dataResult.indexOf(':')+1,dataResult.length-1));  /*已扫描数量*/
                                
                                }
                        }));
                       
                    } 
                    
                }
            }
            })
        });

 

 

 

 

结果:本地测试的时候,不会有问题,发布到公司内部服务器上,录入数据一段时间之后,就卡死了

问题补充:

灰太狼的梦想的主页 灰太狼的梦想 | 初学一级 | 园豆:26
提问于:2018-06-06 11:52

建议给代码加上高亮

dudu 5年前

@dudu: 好

灰太狼的梦想 5年前
< >
分享
最佳答案
0

确定不是数据库的问题吗

收获园豆:200
、熙和 | 小虾三级 |园豆:1508 | 2018-06-06 12:45

问题解决了,是SQLHelper的链接未关闭导致的,谢谢了

灰太狼的梦想 | 园豆:26 (初学一级) | 2018-06-06 13:37
其他回答(2)
0

建议先排查一下问题是否出在数据库层面,比如查询的字段是否加了索引

dudu | 园豆:31075 (高人七级) | 2018-06-06 12:47

问题解决了,是SQLHelper的链接未关闭导致的,谢谢了

支持(0) 反对(0) 灰太狼的梦想 | 园豆:26 (初学一级) | 2018-06-06 13:38
0

看看有没有办法减少ajax数量 然后检查下是不是服务器有问题 

思念断了线 | 园豆:263 (菜鸟二级) | 2018-06-06 13:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册