MVC WebApi跨域ajax接受post数据笔记

后端api代码示例:

               [HttpPost]
        public string callbackUrl([FromBody]SZRCallBackModel cbm)
        { 
            try
            {
                if (cbm == null)
                    return "";
                string CALLBACKTYPE = cbm.CALLBACKTYPE;
                string ERROR_CODE = cbm.ERROR_CODE;
                string IDNO = cbm.IDNO;
                string NAME = cbm.NAME;
                string RESULT = cbm.RESULT;
                string CUSTID = cbm.CUSTID; 
                       }
                }

前端ajax,注意选择post数据类型为 json:

$.ajax({
          url: "/api/Exams",
          type: "post",
          dataType: "json",
          contentType: 'application/json; charset=utf-8',
          data: JSON.stringify(json),
 
          success: function (data) {
              alert(data);
          }
      }).fail(
function (xhr, textStatus, err) {
    alert('Error: ' + err);
});
原文地址:https://www.cnblogs.com/x-poior/p/5644390.html