Rosdi Kasim
Rosdi Kasim

Reputation: 26016

The most concise way to submit javascript array to server?

I need to submit all selected JQGrid row ids to the server.

var rows = $("#grid").getGridParam("selarrrow"); 

Then on the server I would like to do this.

String[] rows =  request.getParameterValues("rows");

Now what is the simplest way to submit rows to the server? Must I use POST?

Upvotes: 0

Views: 1011

Answers (3)

Lakhats
Lakhats

Reputation: 11

When comma comes in the values, server code will split this as two different value. So best way to send value is by creating questring value by looping all the rows. The link below has solved the similar scenario.

Source: http://lakhats.blogspot.com/2010/09/post-javascript-array-to-server-using.html

Upvotes: 1

Rosdi Kasim
Rosdi Kasim

Reputation: 26016

Thanks Konamiman, I opted for this,

$.ajax({
    type: "POST",
    url: "process.jsp",
    data: "rows=" + $("#grid").getGridParam("selarrrow"),
    success: function(){
        alert("submitted.");
    }
}); 

Then on the server I did this,

String[] rows =  request.getParameter("rows").split(",");

Upvotes: 0

Related Questions