Re: [問題] 請問Exception相關問題(ashx 搭配jQuery)
※ 引述《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
02/28 09:44, 1F
→
02/28 09:44, , 2F
02/28 09:44, 2F
→
02/28 09:44, , 3F
02/28 09:44, 3F
→
02/28 09:44, , 4F
02/28 09:44, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章