$.post submission parameter problem

the page submits parameters through the $.post method

var json = JSON.stringify(allData);
    $.post("/deleteUser",
            json,
            function(data){
                if (data == 10000) {
                    alert("");
                } else {
                    alert("");
                }
    });

however, the parameter passed when submitting is {"userId": "1"}:
it treats the entire json as a key, which results in an exception in the receiving parameter, which should normally be "userId": "1", so how should it be changed?

Mar.07,2021

allData does not need serialization, just pass the object.
try this:

$.post("/deleteUser",
    allData,
    function(data){
        if (data == 10000) {
            alert("");
        } else {
            alert("");
        }
    });
The format of

is as follows:
$.post (url,data,success (data, textStatus, jqXHR), dataType)
parameter explanation:
url: is required. Specify which URL to send the request to.
data: is optional. Mapping or string value. Specifies the data to be sent to the server with the request.
success (data, textStatus, jqXHR): is optional. The callback function that is executed when the request is successful.
dataType: is optional. Specifies the data type of the expected server response, and performs intelligent judgment (xml, json, script, or html) by default.


remove JSON.stringify

Menu