简体   繁体   中英

POST request ajax jquery error

I am trying to run post request to parse json format data into the page. 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). I guess it should be some syntax error since the get method works ok. 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 .

JSON.stringify your data:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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