看板 Ajax 關於我們 聯絡資訊
※ 引述《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
johnny9144: 會掉到success其實根本來說應該是要回到你的.ashx這 02/28 09:44
johnny9144: 支程式,因為他一定有回傳結果給client,才會觸發succ 02/28 09:44
johnny9144: ess ,建議先用console 把success 第一個參數印出來 02/28 09:44
johnny9144: 看看到底收到了什麼東西 02/28 09:44