View Full Version : ajax, updating a table order

04-05-2006, 11:44 PM
using a table created from an ajax-returned dataset like this:

1 id#1
2 id#2
3 id#3 -> currently editing

i have a textbox that allows a user to move the position of the item "currently editing" by recreating the ajax dataset and rebuilding the table.

the order of the items is then saved to a DB thru another ajax call.

the problem. shifting the items and saving to the DB works find once, but any attempt to save the items again resulst in the javascript code reading the table that was saved previously.

so if i save the table as
1 id#1
2 id#3
3 id#2

and then shift the table to
1 id#3
2 id#1
3 id#2

the javascript function will pick up the order as being stuck as the top one.
i am guessing that my problem is the DOM is not updating, and i need to refresh it, but i cannot use a typical page refresh (ajax constraint). anyone have any advice on this?


function saveItemOrder()
var env = getEnv();
var user = getUser();
//read the table for items and order, submit each to ajax call to upd item
var itemId;
var itemOrderNum;
var itemOrderTbl = document.getElementById('tblItemOrder');

var arItemOrder = " ";
for (var i=0; i<itemOrderTbl.rows.length;i++)
var iRow = itemOrderTbl.rows[i];
itemId = iRow.id.split("x")[1];
itemOrderNum = itemOrderTbl.rows[i].cells[1].innerHTML;
var itemIdOrderNum = itemId + "|" + itemOrderNum + "|";
if (i != 0)
arItemOrder += itemIdOrderNum;
arItemOrder = itemIdOrderNum;

WebPubHome.saveItemOrderwAR(env, user, arItemOrder, callback_saveItemOrder);

04-06-2006, 04:48 PM
Well, it appears that you're relying on the state of the dom to tell you what order things are in, no?

Though, re-reading your post, I'm not completely sure what the problem is.

04-06-2006, 05:34 PM
To me it sounds like maybe your Ajax request is being cached by the browser.

Do something with a timestamp if you are using get or change it to a post.


04-06-2006, 11:30 PM
i may have misinterpreted the source of my problem. need to do some more testing, and am debated on reworking my approach. in case you'd like me to clarify what i was talking about accomplishing:

i dynamically create a table where each row correspondes to one object in a list. the number of objects is drawn by the returning dataset of a select statement. that's what this is:
Cell Cell
|Object 1 | ID for obj 1 | |textbox| |button|
|Object 2 | ID for obj 2 |

user is 'editing' object 2, row is highlighted to show this, user can enter a new position in the list for the object, (example, user puts a 1 in the textbox, clicks the button, and object #2 moves to the first row, pushes the other rows down)

then user can save the order to the database to retain.

problem was, it was saving the updated order once, but requests to save mutiple times were not updating, they were all coming in the way the first time the user saved. but there may be a couple possible errors in code, i'll need to go through and figure it all out. thanks for your time anyway, and if anyone wants more info or code sample let me know.

also, to note, i'm developing in .net, and using the dll found here: http://ajax.schwarz-interactive.de/vbnetsample/default.aspx