Re: [問題] 請問Exception相關問題(ashx 搭配jQuery)

看板Ajax作者 (dinotw)時間9年前 (2016/02/05 12:18), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《valda (valda)》之銘言: : ashx code : try : { : XXXXXXX : context.Response.Write(JsonConvert.SerializeObject(dt)); : } : catch (Exception ex) : { : context.Response.Write(ex.ToString()); : } : jQuery : $.ajax({ : type: "post", : url: "XXXX.ashx", : data: 'StartMonth=' + $("#txtStartMonth").val() + "&EndMonth=" + : $("#txtEndMonth").val(), : success: function (response, status, xhr) { : ParseCTMData(response); : }, : error: function (xhr, status, error) { : console.log('xhr---->'); : console.log(xhr.status); : console.log(xhr); : console.log('<----xhr'); : console.log('status---->'); : console.log(status); : console.log('<----status'); : console.log('error---->'); : console.log(error); : console.log('<----error'); : alert('error code:' + xhr.status + ',error message:' + error); : } : }) : 如果ashx中真的有error產生,jQuery還是會掉到success中的迴圈,不會跑到error中 : ,請問要如何設計exception handle較好呢? : 感謝 例外一個做法 經過try他輸出的值多給他一個欄位叫result:true catch的話就 result:false 然後到success判斷的時後 if(response.result == true){ }else{ } 這樣如何 -- A跟B是好朋友,然後A喜歡C [我跟你是好朋友,我幫你追C] B看著A說著 A很感動 然後B就追到C了 這就是ABC理論 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.127.37.46 ※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1454645880.A.E27.html

02/28 09:44, , 1F
會掉到success其實根本來說應該是要回到你的.ashx這
02/28 09:44, 1F

02/28 09:44, , 2F
支程式,因為他一定有回傳結果給client,才會觸發succ
02/28 09:44, 2F

02/28 09:44, , 3F
ess ,建議先用console 把success 第一個參數印出來
02/28 09:44, 3F

02/28 09:44, , 4F
看看到底收到了什麼東西
02/28 09:44, 4F
文章代碼(AID): #1Mj29uud (Ajax)
文章代碼(AID): #1Mj29uud (Ajax)