Using jquery to make a POST, how to properly supply 'data' parameter?

后端 未结 5 698
生来不讨喜
生来不讨喜 2020-11-30 11:01

I\'d like to make an ajax call as a POST, it\'s going to go to my servlet. I want to send parameterized data, like the following:

var mydata = \'param0=some_         


        
5条回答
  •  Happy的楠姐
    2020-11-30 11:43

    You need this part:

    data: JSON.stringify({
        BarcodeNumber: $('#shipmentId-input').val(),
        StatusId: $('[name="StatusId"]').val()
    }),
    

    Full object :

    $.ajax(
        {
            url: "/Agent/Shipment/BulkUpdate",
            method: "POST",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify({
                BarcodeNumber: $('#shipmentId-input').val(),
                StatusId: $('[name="StatusId"]').val()
            }),
            success: function (data, textStatus, jqXHR) {
                if (textStatus== "success") {
                    alert(data);
                    // Handel success
                }
                else {
                    // Handel response error
                }
            },
            error: function (jqXHR, textStatus, errorThrown){
                  //Handel connection error
                }
            });
    

提交回复
热议问题