0

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); ?>)},
4

3 に答える 3

1

簡単な修正。jsonをENコード化するのではなく、DEコード化する必要があります。

$args = isset($_REQUEST['gpl_args']) ? $_REQUEST['gpl_args'] : null;
$args = json_decode(stripslashes($args));
print_r($args)
于 2013-05-15T00:56:27.560 に答える
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
于 2013-05-15T01:25:39.830 に答える
-1

実際の引数の代わりに isset() のブール値の結果を出力していませんか?

于 2013-05-15T00:34:14.317 に答える