10

Jquery调用asp.net core web api开发的restful,post类型响应的却是get方法

$.ajax({
type: "POST",
url: "http://localhost:4413/api/WLCode/",
contentType: "application/json; charset=utf-8",
dataType: 'jsonp',
crossDomain: true,
data: { "prod_group": "group1", "prod_type": "type1", "prod_style": "style1", "prod_code": "wlcode1", "prod_desc": "物料", "prod_unit": "个", "is_used": "1" },
success: function (data) { alert(JSON.stringify(data)); },
error: function (data) {
debugger
alert('添加失败!');

            }
        });
                    上面是调用代码,响应的却是下面get方法

    // GET: api/WLCode
    [HttpGet]
    public IEnumerable<string> Get()
    {

        return new string[] { "value1", "value2" };
    }
            下面是post方法代码
              [HttpPost]
    public string Post([FromBody]WLCode wlcode)
    {
        string msg = string.Empty;
        DbHelperSql helperSql = new DbHelperSql(ConnectionString.DefaultConnection);
        if (string.IsNullOrEmpty(wlcode.prod_group))
        {
            msg += "物料组,";
        }
        if (string.IsNullOrEmpty(wlcode.prod_type))
        {
            msg += "物料小类,";
        }
        if (string.IsNullOrEmpty(wlcode.prod_type))
        {
            msg += "物料类型,";
        }
        if (string.IsNullOrEmpty(wlcode.prod_code))
        {
            msg += "SAP物料编码,";
        }
        if (string.IsNullOrEmpty(wlcode.prod_desc))
        {
            msg += "物料名称,";
        }
        if (string.IsNullOrEmpty(wlcode.prod_unit))
        {
            msg += "主计量单位,";
        }
        if (!string.IsNullOrEmpty(msg))
        {
            msg += msg.TrimEnd(',');
            msg += "不能为空";
        }
        else
        {
            try
            {
                string strsql = "INSERT INTO InterFace_WLCode(prod_group,prod_type,prod_style,prod_code,zl_prod_code,zt_prod_code,prod_desc,long_desc,prod_unit, is_used) "
              + "VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')";
                int i = helperSql.ExecuteSql(string.Format(strsql, wlcode.prod_group, wlcode.prod_type, wlcode.prod_style, wlcode.prod_code, wlcode.zl_prod_code, wlcode.zt_prod_code, wlcode.prod_desc, wlcode.long_desc, wlcode.prod_unit, wlcode.is_used));
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
        }

        return msg;

    }
            用postman工具测试是没问题的,但是用自己写的jQuery调用就会有问题,用f12追踪不知道怎么类型也是get。我调用方法明明写的是type=post.请哪位大神指教一下
查看全部
freeds
freeds
2018/11/05 04:50
  • asp.net
  • web api
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复