码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-07-05 18:55:44      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:

后端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);
});

 

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

标签:

原文地址:http://www.cnblogs.com/x-poior/p/5644390.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!