遇到json_decode解析不了的前端代码:
if ($("#json").val()!='' && $("#uri").val()!=''){ var dataJson=JSON.parse($("#json").val()); $.ajax({ url: "<!--{$base_path}-->manage/tools/getFoxJsonData/", type: "post", data:dataJson, contentType: "application/json", timeout: 5000, //超时时间:30秒 async: false,//false-同步(当这个ajax执行完后才会继续执行其他代码);异步-与其他代码互不影响,一起运行。 dataType: "json", success: function (data) { // console.log(data); $("#red").val(data.res); }, error: function (data) { } }); }
正确的前端代码:
$.ajax({
                url: "<!--{$base_path}-->manage/tools/getFoxJsonData/",
                type: "post",
                data:JSON.stringify([dataJson]),
                timeout: 5000, //超时时间:30秒
                async: false,//false-同步(当这个ajax执行完后才会继续执行其他代码);异步-与其他代码互不影响,一起运行。
                dataType: "json",
                success: function (data) {
                    // console.log(data);
                    $("#red").val(data.res);
                }, error: function (data) {
                }
            });后端代码:
$content = file_get_contents('php://input');
        var_dump(json_decode($content,true));
        exit;