简体   繁体   English

javascript表到数组发送到PHP

[英]javascript table to array send to php

I have a 5 column table. 我有一个5列表。 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. 将表数据上传到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. 您不必发送整个两列,如果用户正在播放的数据未被其他来源同时篡改,您只能将用户以(以下的形式)完成的移动发送回服务器( old_index => new_index)对,或者您的数据可能不一定是索引的任何排序字段,方便地在JSON对象中。 Your JSON object should look something like this: 您的JSON对象应如下所示:

[{"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. 回到服务器代码中,只需将订购字段从旧值更改为新值即可。

试试这个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. 序列化帖子或JSON对象都应该可以正常工作。 Most of the work will be on the backend php anyways. 无论如何,大部分工作都将在后端php上。

I personally prefer using JSON data, as its easier manipulated. 我个人更喜欢使用JSON数据,因为它更容易操作。 I also believe it takes up less space than serialized data. 我也相信它比序列化数据占用更少的空间。

Correct me if im wrong. 如果我错了纠正我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM