一个.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。