发送post数组参数

时间:2014-05-23 11:05:15

标签: jquery

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

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

我没有看到数据数组

enter image description here

我该怎么做?

enter image description here

2 个答案:

答案 0 :(得分:2)

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",

$ .ajax的数据属性不需要引号。

另一种方法是对数组进行字符串化

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

答案 1 :(得分:0)

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(''); }
    });

这是快照

http://i.stack.imgur.com/tMRGA.png