简体   繁体   English

POST请求ajax jquery错误

[英]POST request ajax jquery error

I am trying to run post request to parse json format data into the page. 我正在尝试运行发布请求以将json格式的数据解析到页面中。 An example query is: 查询示例为:

    $("#click").click(function () {
            $.ajax({
                type: "POST",
                url: "http://ut-pc-236:9000/kanye/flow/search",
                contentType: "application/json;charset=UTF-8",
                data: {
                        "fromDate":"2011-01-01",
                        "toDate":"2011-03-16T14:35:00Z",
                        "limitTotalFlows":1000,
                        "operator":"AND",
                        "keyValues":[ "J0419:E", "J0410:AMPY", "J1043:BEDFORD" ]
                        },
                success: function (data) {
                    console.log(data);
                }
            });
        });

but it gives an error - bad request (400). 但它给出了一个错误-错误的请求(400)。 I guess it should be some syntax error since the get method works ok. 我猜应该是语法错误,因为get方法可以正常工作。 If anyone can help I would really appreciate it. 如果有人可以提供帮助,我将非常感激。 Thanks 谢谢

You're not sending a valid json object as you claim to be doing with the contentType . 您没有像声称对contentType那样发送有效的json对象。

JSON.stringify your data: JSON.stringify您的数据:

data: JSON.stringify({ 
    "fromDate":"2011-01-01",
    "toDate":"2011-03-16T14:35:00Z",
    "limitTotalFlows":1000,
    "operator":"AND",
    "keyValues":[ "J0419:E", "J0410:AMPY", "J1043:BEDFORD" ]
}),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM