duanbu1998 2013-05-15 00:31
浏览 33
已采纳

没有在PHP中获取json数组

I am passing a json in my ajax request but it is just returning 10 every time, why??

whay my array in not getting passed??

Here is my code:

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);
            }
        });
    });
}); 

and:

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

Update:

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

3条回答 默认 最新

  • dongping4901 2013-05-15 00:56
    关注

    Simple fix. You have to DE-code the json, not EN-code it.

    $args = isset($_REQUEST['gpl_args']) ? $_REQUEST['gpl_args'] : null;
    $args = json_decode(stripslashes($args));
    print_r($args)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100