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?
- <table>
- <tbody>
- <tr>
- <td><span>1</span><input id="1" type="text" class="sortnum" /></td>
- </tr>
- <tr>
- <td><span>1</span><input id="2" type="text" class="sortnum" /></td>
- </tr>
- <tr>
- <td><span>7</span><input id="3" type="text" class="sortnum" /></td>
- </tr>
- <tr>
- <td><span>7</span><input id="4" type="text" class="sortnum" /></td>
- </tr>
- <tr>
- <td><span>6</span><input id="5" type="text" class="sortnum" /></td>
- </tr>
- </tbody>
- </table>
- $('.updateSort').bind('click',function(e){
- // select inputs and sort them
- var $inpArr = $('input.sortnum').sort(function(a,b){
- var keyA = parseInt(a.value);
- var keyB = parseInt(b.value);
- return keyA < keyB ? -1 : keyB < keyA ? 1 : 0;
- }),
- // declare arrays
- sortlist = [],
- typelist = [];
- // loop through inputs
- $inpArr.each(function(){
- // add id of this input to sortlist
- sortlist.push(this.id.split('-')[1]);
- // get status id
- var status_id = parseInt($(this).prev().text());
- // if status_id is less than 5, this is a category, else, this is an item
- if (status_id < 5) {
- // this is a category
- typelist.push('cat');
- } else {
- // this is an item
- typelist.push('item');
- }
- });
- // convert arrays to lists
- sortlist.join(',');
- typelist.join(',');
- // post to server
- $.post('index.cfm',{action:'ajax',method:'updateSort',sortlist:sortlist,typelist:typelist});
- e.preventDefault();
- });
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