jahyax Posted January 21, 2015 Share Posted January 21, 2015 (edited) how do you retrieve each value on a jQuery serialize array var datArr = $("form").serializeArray(); $.ajax({ url: "<path to php file>", type: "POST", headers: {"cache-control": "no-cache"}, data: datArr, dataType: "json", success: function(result){ console.log(result.returned_val); } }); <form> <input id="val1" name="val1" type="text" value="" /> <input id="val2" name="val2" type="text" value="" /> </form> 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 January 21, 2015 by jahyax (see edit history) Link to comment Share on other sites More sharing options...
FullCircles Posted January 22, 2015 Share Posted January 22, 2015 (edited) 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 January 22, 2015 by FullCircles (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now