开发者

$.getJSON doesn't call the "successful" function

I have an issue with .getJSON.

I have these two calls, but the first alert is never shown:

<script type="开发者_JS百科text/javascript" language="javascript">

    $.getJSON('@Url.Action("ChartData")',null,
        function (rdata) {

            alert('data');

        });

        $.post('@Url.Action("ChartData")', null,
        function (rdata) {

            var rdataE = eval(rdata);
            alert(rdata.data);

        });

</script>

I have this controller action:

    public JsonResult ChartData()
    {
        return Json(new { data = "my data" });
    }

I have a breakpoint in the last line, and I can see how it is called twice, but for a reason I don't understand, in the first call the alert is never shown.

I have added the following code at the beginning:

$(document).ajaxError(function (event, request, settings, thrownError) {
    alert('error!');
});

And I can see that there is an error, but I don't know how to check which.

Any idea?

Cheers.


Try changing your controller action return to this:

return Json(new { data = "my data" }, JsonRequestBehavior.AllowGet);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜