AJAX請求.net controller數據交互過程

AJAX發出請求ajax

    $.ajax({
        url: "/Common/CancelTaskDeal", //CommonController下的CancelTaskDeal方法
     type:」get」
        async: false,
        cache: false,
        dataType: "json",
        data: {
            pengingTaskId: PENDINGTASKID
        },
        success: function (r) { //沒有異常,獲取返回值  r 爲FeedbackModel 對象
            if (r.Result) {
                layer.alert("處理成功!");
                $("#tbGrid").DataTable().ajax.reload();
            } else {
                layer.alert("處理失敗!");
            }
        },
        error: function (err) {    //url無效,請求失敗;有Exception異常,沒有捕獲時。
            showPromptModel("處理失敗");
        }
});

Controller中的CancelTaskDeal()方法作出應答json

        public JsonResult CancelTaskDeal(string pengingTaskId)
        {
            try
            {
                WorkFlowHelper.CancelTaskDeal(pengingTaskId);
                return Json(new FeedbackModel { Result = true }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception e)
            {  //此處返回的 Json 格式能夠本身定義  
          // JsonRequestBehavior.AllowGet。解決報錯:此請求已被阻止,由於當用在 GET 請求中時,會將敏感信息透漏給第三方網站。
          //或者將ajax請求 改成 post
          return Json("錯誤");
                 return Json(new FeedbackModel { Result = false , MsgCode =」失敗」}, JsonRequestBehavior.AllowGet);
            }
           
        }
FeedbackModel 對象詳情:

{Result: false, MsgCode: null, FId: null}async

  FId:nullpost

  MsgCode:null網站

  Result:falseurl

  __proto__:Objecspa

相關文章
相關標籤/搜索