ajax .post variable name problems

ajax .post variable name problems

I've used jQuery ajax and .post a lot, and several times within the very application that i'm having issues with, but I've never run into this issue before.

I've got a table of items and categories, sorted by a sort number. in the same cell that the sortnum input is in, there is a span with a status id that differentiates between items and categories so i can modify the correct records in the correct database table.

First, i select all of the inputs and then sort them by the value of the input. next, i loop through the inputs, creating two arrays: one array contains the type of entry, and the other contains the id of the entry.

After the loop, i join each array into its own variable, sortlist and typelist. Next, i perform a .post passing the two lists to my server.

The problem is, on the server side, those two variables are getting a "[]" appended to the end of them, and since i'm working in coldfusion, the only way to get data from them is with evaluate. I can get by using evaluate(), but i'd rather not have to. So far i haven't found a way to get the value of this variable. has anyone else ran into this issue and found a solution?
  1. <table>
  2.       <tbody>
  3.             <tr>
  4.                   <td><span>1</span><input id="1" type="text" class="sortnum" /></td>
  5.             </tr>
  6.             <tr>
  7.                   <td><span>1</span><input id="2" type="text" class="sortnum" /></td>
  8.             </tr>
  9.             <tr>
  10.                   <td><span>7</span><input id="3" type="text" class="sortnum" /></td>
  11.             </tr>
  12.             <tr>
  13.                   <td><span>7</span><input id="4" type="text" class="sortnum" /></td>
  14.             </tr>
  15.             <tr>
  16.                   <td><span>6</span><input id="5" type="text" class="sortnum" /></td>
  17.             </tr>
  18.       </tbody>
  19. </table>
  20. $('.updateSort').bind('click',function(e){
  21.        // select inputs and sort them
  22. var $inpArr = $('input.sortnum').sort(function(a,b){
  23. var keyA = parseInt(a.value);
  24. var keyB = parseInt(b.value);
  25. return keyA < keyB ? -1 : keyB < keyA ? 1 : 0;
  26. }),
  27.         // declare arrays
  28. sortlist = [],
  29. typelist = [];
  30.         // loop through inputs
  31. $inpArr.each(function(){
  32.                 // add id of this input to sortlist
  33. sortlist.push(this.id.split('-')[1]);
  34.                 // get status id
  35. var status_id = parseInt($(this).prev().text());
  36.                 // if status_id is less than 5, this is a category, else, this is an item
  37. if (status_id < 5) {
  38. // this is a category
  39. typelist.push('cat');
  40. } else {
  41. // this is an item
  42. typelist.push('item');
  43. }
  44. });
  45.         // convert arrays to lists
  46. sortlist.join(',');
  47. typelist.join(',');
  48.         // post to server
  49. $.post('index.cfm',{action:'ajax',method:'updateSort',sortlist:sortlist,typelist:typelist});
  50. e.preventDefault();
  51. });
On the server, sortlist and typelist are defined as form.sortlist[] and form.typelist[] which are not valid variable names in coldfusion.

-- Kevin

------------------------------------------------
http://www.tentonaxe.com - jQuery Snippets and Tutorials