我在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); ?>)},发布于 2013-05-15 08:56:28
简单的解决方法。您必须对json进行DE编码,而不是对其进行编码。
$args = isset($_REQUEST['gpl_args']) ? $_REQUEST['gpl_args'] : null;
$args = json_decode(stripslashes($args));
print_r($args)发布于 2013-05-15 09:25:40
查看你的脚本:
$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-15 08:34:14
您不是要打印isset()的布尔结果而不是实际的args吗?
https://stackoverflow.com/questions/16554912
复制相似问题