简体   繁体   中英

Unable to post data on Jquery ajax

My code to post data to server is like this

  $('#btn').click(function () {

        var myarray = [];
        $("#DocumentList input[type=checkbox]:checked").each(function () {
            myarray.push($(this).attr('uniqueid'));
        });
        alert(myarray);
     
        $.ajax({
            url: "url",
            type: "post",
            dataType: "text",
            data: myarray,
            success: function (response) {
               
            },
            error: function (jqXHR, textStatus, errorThrown) {
                console.log(textStatus, errorThrown);
            }
        });
    });

on alert I am getting the data I want to post to server, But when I inspect the call on Chrome,I can see that data is not getting posted (screenshot added below). What can be the reason for this behavior? 在此处输入图片说明

jQuery does not expect you to pass an array of strings to data .

It can't process that usefully.

Typically you would pass an object of name: value pairs:

data: { something: myarray }

… which will URL encode it with the something[] extended syntax introduced by PHP.

You will need to make sure the encoding you send matches whatever the server expects though.

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