php / jquery:发布表单数据

i wrote a grid widget for editing data from a database and i'm looking for a more convenient way for sending the data to my saving-script.

the form contains textboxes and the following database structure:

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

currently i'm adding the recordID to the fieldname, sending i this way:

first_name/1=andy&last_name/1=smith&first_name/2=tom.....

the problem is that on the server script i need to parse the recordID's for proper saving. is there a more convenient way where i can wrap each record by its recordID?

such as: record1 = firstname:andy, last_name:smith | record2 = ... ?

i'm building the post string by jQuery. thanks!

form your data into an array (arrayOfData for this example), then you can use a jQuery ajax call to send it as a string to php (phppage.php in this example). something like the following will work. to use this you need JSON.js from here for the stringify function.

$.post("phppage.php",{
    fieldName:JSON.stringify(arrayOfData)
},function(return){
   //whatever
});

this will need to be parsed in php like

$incArray = json_decode(fieldName, true);

only an example, not all the work is done for you here.

Try to name your fields like this:

records[1][first_name]=andy&records[1][last_name]=smith&records[2][first_name]=tom.....