I need to convert a javascript array into a string readable by php "unserialize".
In my javascript, I have:
var params = {};
params['showTitle'] = 0;
params['class'] = '';
params['ajax'] = 0;
params['ajaxDom'] = '';
params['what'] = 'defi';
params['color'] = 'dark';
The output I really need to get is this :
a:6:{s:9:"showTitle";i:0;s:5:"class";s:0:"";s:4:"ajax";i:0;s:7:"ajaxDom";s:0:"";s:4:"what";s:4:"defi";s:5:"color";s:4:"dark";}
Why do I need this? because the output is red on the server side (with php function unserialize) and I cannot change this (it's part of a framework).
My question is : how to convert the javascript array? I've tried (but didn't work):
params = JSON.stringify(params);
params = $.param(params);
It should be easy but I'm stuck... Thank you !
serialize(), when there is JSON ...unserializeloose on parameters coming from the outside is not recommended – it can be a security risk, because it can under certain conditions be used to initiate objects from classes in the script. A framework should not be doing this in the first place.