问题描述
代码只能执行了一次,第二次点击的时候,就没有返回的数据了,求解!刚开始用ajax请各位大神多指点!谢谢了!$("#DataKeep").click(function(){varRowAllData=All_Expense();//返回数据$.ajax({url:'Data_Keep.ashx',//ajax提交路径type:'post',//提交方式data:{Application_Type:$("#Application_Type").val(),Distributor_Name:$("#Distributor_Name").text(),LeiXin:$("#LeiXin").text(),BianMa:$("#BianMa").text(),DangAnHao:$("#DangAnHao").text(),RenYuanDangAnHao:$("#RenYuanDangAnHao").val(),ShenQingRen:$("#ShenQingRen").text(),ShenQingRiQi:$("#ShenQingRiQi").text(),LiuShuiHao:$("#LiuShuiHao").text(),BanShiChu:$("#BanShiChu").text(),ShenQingBianHao:$("#ShenQingBianHao").text(),ZhiXing:$("#ZhiXing").val(),DiDian:$("#DiDian").val(),Application_Explain:$("#Application_Explain").val(),AllData:RowAllData,},//提交参数success:function(result){//ajax请求完成时执行,result为返回的结果alert(result);},error:function(){alert("ajax请求处理错误");}});})
publicclassData_Keep:IHttpHandler{privatestringmyConnectionString=ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString;publicvoidProcessRequest(HttpContextcontext){//接收页面传参//intid=0;//int.TryParse(context.Request.Form["id"],outid);stringApplication_Type=context.Request.Form["Application_Type"];//申请单类型stringDistributor_Name=context.Request.Form["Distributor_Name"];//经销商名称stringLeiXin=context.Request.Form["LeiXin"];//经销商类型<scriptsrc="File_Style/JavaScript_Css/Home.js"></script>stringBianMa=context.Request.Form["BianMa"];//经销商编码stringDangAnHao=context.Request.Form["DangAnHao"];//经销商档案号stringRenYuanDangAnHao=context.Request.Form["RenYuanDangAnHao"];//申请人档案号(隐藏)stringShenQingRen=context.Request.Form["ShenQingRen"];//申请人stringShenQingRiQi=context.Request.Form["ShenQingRiQi"];//申请日期stringLiuShuiHao=context.Request.Form["LiuShuiHao"];//申请单流水号stringBanShiChu=context.Request.Form["BanShiChu"];//办事处stringShenQingBianHao=context.Request.Form["ShenQingBianHao"];//申请单编号stringZhiXing=context.Request.Form["ZhiXing"];//执行单位stringDiDian=context.Request.Form["DiDian"];//地点或渠道stringApplication_Explain=context.Request.Form["Application_Explain"];//促销申请说明stringAllData=context.Request.Form["AllData"];//全部门店明细//这里进行数据处理或对数据库的操作//SqlConnectionmyConnection=newSqlConnection(myConnectionString);myConnection.Open();//存入主表数据S_Promotion_AMstringcmdText="insertintoS_Promotion_AM(Promotion_MNum,P_WH_BSC,P_WH_Fnum,P_WH_Name,KH_Name,KH_Num,KH_Fnum,Promotion_MType,Promotion_Mcode,Promotion_Coutent,Promotion_Date,Promotion_Implement,Promotion_Place)values('"+LiuShuiHao+"','"+BanShiChu+"','"+RenYuanDangAnHao+"','"+ShenQingRen+"','"+Distributor_Name+"','"+BianMa+"','"+DangAnHao+"','"+Application_Type+"','"+ShenQingBianHao+"','"+Application_Explain+"','"+ShenQingRiQi+"','"+ZhiXing+"','"+DiDian+"')";SqlCommandmyCommand1=newSqlCommand(cmdText,myConnection);myCommand1.ExecuteNonQuery();myConnection.Close();////context.Response.ContentType="text/plain";//返回数据类型context.Response.Write(AllData);//返回数据}publicboolIsReusable{get{returnfalse;}}}
解决方案
解决方案二:
用fiddler调试下,看看客户端js提交的是什么
解决方案三:
在后台代码中做个标记,判断是否第一次请求就可以了!
解决方案四:
chome按f12,查看返回数据后,第二次再次点击的时候,js是否报错。断点调试你的ashx文件,第二次是否后台代码报错
解决方案五:
$.ajax({url:"UserAtlas.ashx",type:"get",cache:false,async:false,data:{random:Math.random()},dataType:"json",success:function(data){if(data!=null){$(data.result).each(function(i,n){});}}});
解决方案六:
你应该根据调试而逐步深入。例如通过http调试器看到第二次有上行数据,但是下行是5xx状态,那么你就可以调试asp.net程序,看看程序异常。另外,你应该在vs上开发,不要在其它不靠谱的开发工具上开发,更不要用什么notepad.exe来写代码然后直接放到网站上。如果你在vs上开发,你的调试器就会停留再抛出异常的语句上,例如停在myCommand1.ExecuteNonQuery()上,并且有错误提示、详细信息窗口、堆栈调用窗口、变量监视窗口、调试命令行窗口,等等各种调试工具。不调试,永远不能成为一个专业程序员。
解决方案七:
打开Fibug,查看每次点击时候的请求信息
解决方案八:
ajax缓存问题,在提交请求的地址上加个随机数,如url:"UserAtlas.ashx?rnd="+newDate()