开发者

JSON + jQuery $.post + Django --> parsererror - SyntaxError: invalid label

For some reason I'm getting "SyntaxError: invalid label" error when I receive JSON data (see below) from a django function. Any ideas?

{ "id": "325", "from_date": "09-19-2011", "to_date": "09-20-2011" }

This is the jQuery code I'm using:

$(".edit_rec").click(function () {
    var rec_id =开发者_运维百科 $(this).attr('name');
    $.post("/edit/", {
        editid: rec_id
    }, function (json) {
        var content = $.parseJSON(json);
        var to = new String(content.to_date);
        var from = new String(content.from_date);
    });
});


you need to add "json" after the callback to let jquery know that the return data should be json. jQuery will then automatically parse your json string into a JavaScript object.

$(".edit_rec").click(function () {
    var rec_id = $(this).attr('name');
    $.post("/edit/", {
        editid: rec_id
    }, function (content) {
        var to = new String(content.to_date);
        var from = new String(content.from_date);
    },"json");
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜