Javascript Ajax POST请求问题与Flask不宁

Javascript Ajax POST请求问题与Flask不宁,javascript,jquery,python,json,ajax,Javascript,Jquery,Python,Json,Ajax,我正在尝试使用jQuery和Ajax向我的API发送POST请求 $.ajax({ url: '/api/Orders', headers: { contentType: "application/json" }, type: "POST", data: JSON.stringify({'description':'test'}), }); 当我使用postman(chrome扩展名)时,POST请求很好,一切都很好 如果我试图将上述代码

我正在尝试使用
jQuery
Ajax
向我的API发送
POST
请求

$.ajax({
    url: '/api/Orders',
    headers: {
        contentType: "application/json"
    },
    type: "POST",
    data: JSON.stringify({'description':'test'}),
});
当我使用
postman
(chrome扩展名)时,
POST
请求很好,一切都很好

如果我试图将上述代码与
AJAX
一起使用,则响应为:

message:"Request must have "Content-Type: application/json" header"

我觉得这很奇怪,因为我设置了
contentType:“application/json”

您是否尝试将属性数据类型设置为json

您的代码如下所示:

$.ajax({
   url: '/api/Orders',
   headers: {
      contentType: "application/json"
   },
   type: "POST",
   data: JSON.stringify({'description':'test'}),

   dataType: "json"
});

6个小时后,我找到了正确的答案

    $.ajax({
        url: 'http://127.0.0.1:5000/api/Orders',
        headers: {
            accepts: 'application/vnd.api+json'
        },
        contentType: "application/json",
        type : 'post',
        data: JSON.stringify({
            'description' : 'test'
        }),
        dataType: "json",
        success: function(data) {
            console.log(data);
        }
    });

不幸的是,这不起作用。同样的错误。谢谢你的回答。