POST a js::array in JSON, got “undefined:undefined”

I have a javascript array in the frontend, and I want to post it to my Tomcat server.

I'm using this code but it's not working as

        console.log("preview list. postUsers()");
        console.log(Ext.getCmp("preview-container").getUsers());
        $.ajax({
            url: "url",
            type: "POST",
            data: Ext.getCmp("preview-container").getUsers(),
            dataType: "json",
            success: function(rst){
                switch (rst){
                case true:
                    alert("success");
                    break;
                case false:
                    alert("failed");
                    break;
                }
            },
        });

The object is like this:

preview list. postUsers() 
["18241", "44598", "46558"]

But the POST result is like this:

   undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&undefined=undefined&

Which is parsed like this:

undefined: undefined ...

Am I missing anything important?

Answers


Looks like you are missing the post request parameter name

console.log("preview list. postUsers()");
console.log(Ext.getCmp("preview-container").getUsers());
$.ajax({
    url: "url",
    type: "POST",
    //send the users using parameter `users`
    data: { users: Ext.getCmp("preview-container").getUsers()},
    dataType: "json",
    success: function(rst){
        switch (rst){
            case true:
                alert("success");
                break;
            case false:
                alert("failed");
                break;
        }
    },
});

Need Your Help

Strange application crash

c++ ubuntu-10.04

I have this C++ application running on a Ubuntu Lucid 10.04.3 LTS which is crashed and the reason really escapes me.

Completing Oauth without the use of threading

c#

I am not exactly sure how to explain this so I'll give it my best shot.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.