user3575477
user3575477

Reputation: 31

send post array parameter

var type = new Array("Competency", "Gender", "Global" );

$.ajax({
  url: "/Crew/Crew/GetDefinationType/",
  type: "POST",
  data: "{type:'" + type + "'}",
  contentType: "application/json",
  dataType: "json",

I do not see the array of data

enter image description here

How can I do that?

enter image description here

Upvotes: 2

Views: 43

Answers (2)

var jsonObj = new Array("Competency", "Gender", "Global");

    $.ajax({
        type: 'POST',
        contentType: "application/json; charset=utf-8",
        url: 'Home/getArray',
        data: JSON.stringify({ "obj":  jsonObj}),
        async: false,

        success: function (response) {
            alert("");
        },

        error: function ()
        { console.log(''); }
    });

Here is snap shot

https://i.sstatic.net/tMRGA.png

Upvotes: 0

mohamedrias
mohamedrias

Reputation: 18566

var type = new Array("Competency", "Gender", "Global" );
// can also be var type = ["Competency", "Gender", "Global"];

        $.ajax({
            url: "/Crew/Crew/GetDefinationType/",
            type: "POST",
            data: {"type": type },
            contentType: "application/json",
            dataType: "json",

No quotes are required for the data attribute of $.ajax.

Another way, is to stringify the array

$.ajax({
                url: "/Crew/Crew/GetDefinationType/",
                type: "POST",
                data: {"type": JSON.stringify(type) },
                contentType: "application/json",
                dataType: "json",

Upvotes: 2

Related Questions