php/jquery:发布表单数据
我编写了一个用于编辑数据库数据的网格小部件,我正在寻找一种更方便的方法将数据发送到保存脚本 该表单包含文本框和以下数据库结构:php/jquery:发布表单数据,php,jquery,forms,formatting,Php,Jquery,Forms,Formatting,我编写了一个用于编辑数据库数据的网格小部件,我正在寻找一种更方便的方法将数据发送到保存脚本 该表单包含文本框和以下数据库结构: recordID field value field value ---------------------------------------------------------- 1 first_name andy last_name smith 2 first_
recordID field value field value
----------------------------------------------------------
1 first_name andy last_name smith
2 first_name tom last_name jones
3 first_name john last_name connor
目前,我正在将recordID添加到fieldname,并通过以下方式发送:
first_name/1=andy&last_name/1=smith&first_name/2=tom.....
问题是,在服务器脚本上,我需要解析recordID以进行适当的保存。
是否有一种更方便的方法,可以通过记录ID包装每条记录
such as: record1 = firstname:andy, last_name:smith | record2 = ... ?
我正在通过jQuery构建post字符串。
谢谢 尝试按以下方式命名字段:
records[1][first_name]=andy&records[1][last_name]=smith&records[2][first_name]=tom.....
将数据形成一个数组(本例中为arrayOfData),然后可以使用jQuery ajax调用将其作为字符串发送到php(本例中为phppage.php)。像下面这样的东西会起作用。要使用它,您需要为
stringify
函数使用JSON.js from
$.post("phppage.php",{
fieldName:JSON.stringify(arrayOfData)
},function(return){
//whatever
});
这需要像php一样用php进行解析
$incArray = json_decode(fieldName, true);
这里仅举一个例子,并不是所有的工作都为您完成。如何保存数据。ajax还是submit?好主意,但我想我需要使用eval()在php中转换它?不。php会自动将这样的名称转换为数组。因此,您可以在脚本中使用$_POST['records']。