0

I have the following code:

     var ids = [];
     for (var i = 0, row; row = table.rows[i]; i++) {
          if (parseInt(row.cells[0].innerHTML || 0) > 0 ) {
                  ids.push(row.cells[0].innerHTML);
          }
     }

     var submit_data = {name: vname, users:ids};                
     $.ajax({
       url: "/cgi-bin/add_users",
       dataType: "json",
       data: submit_data,
       success: function(data) { 
               $("#").html();
             }
        });

on the server side when i check the type of the variable on the ids, it's a string...All the data is there. But it has a bunch of spaces in between each record.

Any tips on how I get the back end to recognize my array as an array?

Thanks.

EDIT 1

Here's the server side code. All I'm doing right now is logging:

if FORM.name then
        u.log(tostring(type(FORM.users)))
        u.log(FORM.users)
end

The logs show:

Wed May 13 12:25:40 2015 - string
Wed May 13 12:25:40 2015 - 232
233
Wed May 13 12:25:40 2015 - connect to sysdb

The first two entries you see in the log is what is produced by the code in question. I would like an array that looks like [232,233] or even a json array like {1:232,2:233}

Found this post: Pass array to ajax request in $.ajax()

Trying out the suggestions there for now.

EDIT 2

Here's what the query string looks like:

http://testserver/cgi-bin/add_users?name=test&users%5B%5D=231&users%5B%5D=232

Community
  • 1
  • 1
Happydevdays
  • 1,982
  • 5
  • 31
  • 57
  • Please include your server-side code. – Peter Herdenborg May 13 '15 at 12:20
  • @PeterHerdenborg, please check out the edit I've made - EDIT 1. Thanks. – Happydevdays May 13 '15 at 12:27
  • `dataType` tells jQuery what data format to expect the server to return. It doesn't control how the data you send is formatted. You are sending data in the standard form encoding. How that gets handled by the server depends on the library you use to parse the form data and you haven't told us what that is. – Quentin May 13 '15 at 12:41
  • @Quentin I'm using lua. Having said that, I think the issue is with serializing the array. – Happydevdays May 13 '15 at 12:44
  • Side note: you should add tag for your serverside language... CGI is way to general to be useful... Note that more common server side languages like php, JavaScript(nodeJs) or C# could be easier to start server side processing with due to large number of people using them compared to Lua (if you'd ask about game scripting would be other way around). – Alexei Levenkov May 13 '15 at 14:51

0 Answers0