How to submit JSON Data by Request Body in jQuery?

后端 未结 1 699
遇见更好的自我
遇见更好的自我 2021-02-05 21:30

I am not expert in jQuery, consider me fresher. Here is my code which one not responsible for jQuery JSON data submission by Request Body.


         


        
1条回答
  •  清酒与你
    2021-02-05 22:19

    Here is the right code for your desired out put.

    $.ajax({
            url : "/",
            type: "POST",
            data: JSON.stringify([
                {id: 1, name: "Shahed"}, 
                {id: 2, name: "Hossain"}
            ]),
            contentType: "application/json; charset=utf-8",
            dataType   : "json",
            success    : function(){
                console.log("Pure jQuery Pure JS object");
            }
        });
    

    Your must convert JS Object to String and JSON.stringify(JSObject) is the method responsible for that.

    0 讨论(0)
提交回复
热议问题