jquery - How to get JSON.stringify into PHP with json_decode without AJAX? -
say, have this
function submitform() { var data = json.stringify({ "userdata": $('#user_data').val() }) $('<input type="hidden" name="json"/>').val(data).appendto('#myform'); $("#myform").submit(); } now on server side, i've tried:
json_decode($_post['json']); json_decode($_post['json'], true); json_decode(htmlspecialchars_decode($_post['json']), true); all of these return null value when var_dump on page.
i not submitting form via ajax, , not want use application/json submit form because there other fields in form need submitted normal form submission way.
how can this?? need send json php on form submission.
probably magic quotes screw json string , php doesn't recognize anymore. use stripslashes() before hand on json_decode():
$a = json_decode(stripslashes($_post['json'])); var_dump($a);
Comments
Post a Comment