没有在PHP中获取json数组

时间:2013-05-15 00:31:00

标签: php json

我在我的ajax请求中传递一个json,但它每次只返回10,为什么?

我的数组没有通过?

这是我的代码:

jQuery(document).ready(function($){
    $('#list-3 .ajaxcall').click(function(){
        $.ajax({
            type : "GET",
            url : ajaxurl,
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            data : { 
                    gpl_args : JSON.stringify({"cat":"26","posts_per_page":"4","paged":1}),
                    gpl_layout : {"show_thumb":"1","columns":"4","thumb_height":"85","thumb_width":"85","title_link":"1","content_excerpt":"50","posts_per_page":"4"}
            },
            success : function(response) {
                // The server has finished executing PHP and has returned something,
                // so display it!
                $("#list-3").append(response);
            }
        });
    });
}); 

$args       = isset($_REQUEST['gpl_args']);
//$args         = json_encode(isset($_REQUEST['gpl_args']));
print_r($args)

更新

my data inside ajax:
   data    : { gpl_args : JSON.stringify(<?php echo json_encode($args); ?>),
              JSON.stringify(gpl_layout   : <?php echo json_encode($layout); ?>)},

3 个答案:

答案 0 :(得分:1)

简单修复。你必须对json进行DE编码,而不是对它进行EN编码。

$args = isset($_REQUEST['gpl_args']) ? $_REQUEST['gpl_args'] : null;
$args = json_decode(stripslashes($args));
print_r($args)

答案 1 :(得分:0)

查看您的php脚本:

$args       = isset($_REQUEST['gpl_args']);
//$args     = json_encode(isset($_REQUEST['gpl_args'])); 
// $args is false(Boolean type), But not json
print_r($args);  // print_r(false);  is show nothing!!

正确方式:

$json_array[] = isset($_REQUEST['gpl_args']) ? $_REQUEST['gpl_args'] : false;
echo json_encode($json_array);  // will show json string

答案 2 :(得分:-1)

你不打印isset()的布尔结果而不是实际的args吗?