简体   繁体   中英

How to use serializeArray values in php?

I got the resize from a form.

 resize = $('#resize_form').serializeArray();

I put the resize in a hidden and send it to a php page.How to get the resize value in php?

<input type='hidden' name='name_print' value='resize '>

I dump the value in the received php

name_print (String): "[object Object],[object Object],[object Object]  
,[object Object],[object Object]" (79 characters)  

I use firebug and it show this

 [Object { name="name_print", value="5555"}, Object { name="hem_up", value=""},  
 Object { name="hem_up_double", value="0"}, Object { name="hem_up_size", value="0"},  
 Object { name="waist_catch", value=""}]

How to use the data in php? convert it to an array?

I use the JOSN.stringify the data like this

[{"name":"name_print","value":"1111111111"},{"name":"hem_up","value":""},   
{"name":"hem_up_double","value":"0"},{"name":"hem_up_size","value":"0"},  
{"name":"waist_catch","value":""}]

You can't put an array into a form field, you have to convert it into a string first. You can put it in JSON format:

resize = JSON.stringify($('#resize_form').serializeArray());

Then in PHP, you can use json_decode() :

$resize = json_decode($_POST['name_print']);

Try to use serialize() instead of serializeArray() . It creates a string with your form data so you can send it to the server.

   // in your php code
   $resizedata = json_decode(stripslashes($_POST['resize']),true);
   $resizeval = $resizedata['name_print'];
   print_r($resizeval);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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