jquery - PHP read array object from javascript data object -
i create data object in jquery , pass php post method
var pd = { currentpage : 1, rowcount : 10, search : 5 }; post method --> data = pd
in php page if superglobal $_post have this
var_dump($_post) --> array ( [data] => [object object] )
in php how can read $ _post ['data'] values ?
edit (full code)
var pd = { currentpage : 1, rowcount : 10, search : 5 }; pd = json.stringify(pd); redirectpost('index.php', { data : pd }); var redirectpost = function(location, args) { var form = ''; $.each(args, function(key, value) { form += '<input type="hidden" name="'+key+'" value="'+value+'">'; }); $('<form action="'+location+'" method="post">'+form+'</form>').appendto('body').submit(); };
php
$data = json_decode($_post['data']); var_dump($data); <-- null
it looks you're looking json_decode()-function. however, not create php-object, turn array this: $data['currentpage']
. see if more luck this:
$data = json_decode($_post['data']); var_dump($data);
Comments
Post a Comment