开发者

javascript table to array send to php

开发者 https://www.devze.com 2023-03-26 18:02 出处:网络
I have a 5 column table. The table row order is edited moving the rows up or down on the client side by the user, I want to now upload the data so the database can be updated.

I have a 5 column table. The table row order is edited moving the rows up or down on the client side by the user, I want to now upload the data so the database can be updated.

I thought of converting the two columns to a array then send by a serialized post

开发者_运维百科What is the best way to upload the table data to php. I only need the first two columns.?


You don't have to send the whole two columns, if the data the user is playing with is not being tampered with by some other source concurrently, you can send back to the server only the moves done by the user in the form of (old_index => new_index) pairs, or whatever ordering field your data might have not necessarily an index, conveniently in a JSON object. Your JSON object should look something like this:

[{"2": "4"}, {"5": "3"}, {"1", "7"}]

And back in your server code just change the ordering field from the old value to the new one.


Try this http://jsfiddle.net/cJRmM/3/

{col1: [11,12,13,14,15], col2: [21,22,23,24,25]}


Both a serialized post or a JSON object should work fine. Most of the work will be on the backend php anyways.

I personally prefer using JSON data, as its easier manipulated. I also believe it takes up less space than serialized data.

Correct me if im wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消