【发布时间】:2013-07-09 09:12:33
【问题描述】:
a.php
$(document).ready(function() {
$("#submit_form").on("click",function(){
var json_hist = <?php echo $json_history; ?>;
$.ajax({
type: "POST",
url: "b.php",
data: "hist_json="+JSON.stringify(json_hist),
//contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){alert(data);},
failure: function(errMsg) {
alert(errMsg);
}
});
});
})
b.php
$obj=json_decode($_POST["hist_json"]);
var_dump($_POST);
如果我评论
contentType: "application/json; charset=utf-8"
一切正常,但如果取消注释。
var 转储将返回 null。
【问题讨论】:
-
无需在php文件中提供
json_decode。 -
你为什么使用 dataType: "json" ?尝试删除它,因为 b.php 的输出不是 json
-
谢谢,但即使我没有在 php 文件中解码。它在 var 转储中返回 null。 "$history = json_encode($pro_hist);" “var json = ;”我已经编码为 json 类型。但是为什么我不需要使用数据类型 json 呢?谢谢