如何将POST响应推送到数组?

时间:2017-10-18 18:32:01

标签: javascript jquery arrays ajax http-post

我的API有效,响应中的结构如下。

enter image description here

有一个客户端和客户端有多个标头,每个标头都有一个名称和URL,依此类推。

THeader1 

 - TReports 
       - Name
       - URL

THeader 2

  -TReports

       -Name
       - URL

但是我想把它推到数组对象,我可以像下面这样使用它:

myVizes = new Array(
                {
                    'name' : 'Test1',
                    'url'  : 'https://test/views/test/Alert?',

                    'hash' : 'test'
                },
                {
                    'name' : 'Test2',
                    'url'  : 'https://blahblah/views/blah/Alert?',

                    'hash' : 'Test2'
                },
                {
                    'name' : 'Test2e',
                    'url'  : 'https://test/views/test?',

                    'hash' : 'Test'
                }

            );

然而,我的jSon

getURLS: function (ID)

    {

        var data = {};
        if (typeof (_config.clientID) != 'undefined') {
            data.clientID = _config.clientID;
        }
        var outputdata = '';
        $.ajax({

            type: 'POST',
            url: _config.GetHeadersByClientAPI,
            dataType: 'json',
            contentType: 'application/json',
            data: JSON.stringify({TReports:data}),

            success: function (data)
            {
                alert("it works!"+data)
            },

            error: function (xhr, status, error)
            {

                alert("did not work!")
            }



        });


    }

我的数据返回emjpty对象。有什么想法吗?

0 个答案:

没有答案