veccy
veccy

Reputation: 925

javascript table to array send to php

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.?

Upvotes: 0

Views: 133

Answers (3)

Dart
Dart

Reputation: 787

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

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

Upvotes: 1

0xcurb
0xcurb

Reputation: 126

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.

Upvotes: 1

Bodman
Bodman

Reputation: 8046

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.

Upvotes: 0

Related Questions