$.ajax获取不到数据问题解决

$("#updateflow").click(function () {
            $.ajaxSetup({
                contentType: "application/json;charset=UTF-8"
            });

            var flowData = $("#flowdata").val();
            var flowData = JSON.parse(flowData);
            var param = {
                'flowData': JSON.stringify(flowData['data'])
            };
            $.post("/api/index.php/Habo_v2/DiyApi/updateFlowData", JSON.stringify(param), function (jsondata) {
                jsonStr = JSON.stringify(jsondata, null, 4);
                $("#flowdata").val(jsonStr);
                console.log("flowData: ", jsondata);
            }, "json");
        });

 

获取不到数据时,记得 contentType的设置:

       $.ajax({
            type: "post",
            url: "getData.php",
            data: { Skip: Skip, Take: Take },
            //contentType: "application/json; charset=utf-8",//(可以)
            //contentType: "text/xml",//(可以)
            //contentType:"application/x-www-form-urlencoded",//(可以)
            //dataType: "string",
            success: function (data) {
                if (data != "") {
                    $('.thumb').append(data);
                }
                $('#divPostsLoader').empty();
            }
        })

 

posted on 2016-08-16 10:33  星空守望者--jkmiao  阅读(853)  评论(0编辑  收藏  举报