I have a jQuery object which is appended to form field like,
var params = {
'product_id': productId,
'width': width,
'drop': drop
};
$("#sample-form input[name='params']").val(params);
Form looks like,
<form id="sample-form" action="url" method="post">
<input type="hidden" name="params"/>
<button type="submit">Submit</button>
</form>
On receiving this "params" using POST data in PHP, I get string with value "[object Object]"
How do I convert this into array?
I converted jQuery object into stringified JSON as,
$("#sample-form input[name='params']").val(JSON.stringify(params));
In PHP, convert received JSON into PHP array as,
$params = json_decode($_POST['params'], true);
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.