可能重复:
将数据数组从php发送到javascript
我知道有很多这样的问题,但我发现它们都没有那么清楚.
我有一个像这样的Ajax请求:
$.ajax({
type: "POST",
url: "parse_array.php",
data: "array=" + array,
dataType: "json",
success: function(data) {
alert(data.reply);
}
});
Run Code Online (Sandbox Code Playgroud)
我如何将一个JavaScript数组发送到一个php文件,将它解析成php数组的php是什么样的?
我正在使用JSON.
我在这里有这个代码:
case 'resource_list':
if(file_exists('content.php')){
include('../ajax/content.php');
} else {
die('does not exist');
}
$html = render_content_page($array[1],$array[2]);
$slate = 'info_slate';
$reply_array = array(
'html' => $html,
'slate' => $slate
);
echo json_encode($reply_array);
break;
Run Code Online (Sandbox Code Playgroud)
我调试了每个级别,直到json_encode()被调用.但是我在ajax中收到的数据对于html密钥来说是nul.这段代码本质上是另一个案例的复制和粘贴,它只是调用一个函数而不是render_content_page()完美的.
$ reply_array var_exports to:
array (
'html' => '<ol>
<li unit="quiz" identifier=""><img src="img/header/notifications.png"/>Fran?ois Vase Volute Krater</li>
</ol>',
'slate' => 'info_slate',
)
Run Code Online (Sandbox Code Playgroud)