Jump to content

retrieving serialize array


Recommended Posts

how do you retrieve each value on a jQuery serialize array


var datArr = $("form").serializeArray();
url: "<path to php file>",
type: "POST",
headers: {"cache-control": "no-cache"},
data: datArr,
dataType: "json",
success: function(result){
<input id="val1" name="val1" type="text" value="" />
<input id="val2" name="val2" type="text" value="" />
and on my php file is
$datArr = Tools::getValue('datArr');
$arrVars = array();
foreach ($datArr as $key => $value) {
$arrVars = $key;
echo json_encode(array('returned_val' => $arrVars['val1']);
i  get a null on my console.log
How do i properly retrieve serialize array and return them back.
Edited by jahyax (see edit history)
Link to comment
Share on other sites

serializeArray just converts the data into a javascript array. That's then being encoded into JSON by the ajax call and sent over to your php file.


From there, you should just need to run json_decode($datArr, true) to get a usable (associative) array


Missed the return them back bit, for that, you should be able to just return: json_encode($arrVars) , as long as nothing else is being output from the file.

Edited by FullCircles (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...