语法错误Jquery AJAX调用

时间:2015-10-06 17:48:48

标签: jquery ajax

我收到此语法错误,因为我错过了}有人可以请告诉我我可能会忽略的内容......这说第25行,但我看不到它。

错误

SyntaxError: missing } after property list

代码

$(document).ready(function(){
    // What happens when a user hits the "Accept" button on the dealer form
    $(".label_accept").click(function(){
        $('#LabelMaker').modal('hide');

    });

    $('#labelForm').on('submit', function(e){
        e.preventDefault();
        alert($(this).serialize());
        $.ajax({
        // the location of the CFC to run
        url: "index_proxy.cfm",
        // send a GET HTTP operation
        type: "get",
        // tell jQuery we're getting JSON back
        dataType: "json",
        // send the data to the CFC
        data: $('#labelForm').serialize(),
        // this gets the data returned on success
        success: function (data){
            console.log(data);
        }
        // this runs if an error
        error: function (xhr, textStatus, errorThrown){
        // show error
        console.log(errorThrown);
        }
   });
});

2 个答案:

答案 0 :(得分:4)

你错过了一个逗号,然后是一个关闭块。检查我评论为缺失的行。

$(document).ready(function () {
    // What happens when a user hits the "Accept" button on the dealer form
    $(".label_accept").click(function () {
        $('#LabelMaker').modal('hide');

    });

    $('#labelForm').on('submit', function (e) {
        e.preventDefault();
        alert($(this).serialize());
        $.ajax({
            // the location of the CFC to run
            url: "index_proxy.cfm",
            // send a GET HTTP operation
            type: "get",
            // tell jQuery we're getting JSON back
            dataType: "json",
            // send the data to the CFC
            data: $('#labelForm').serialize(),
            // this gets the data returned on success
            success: function (data) {
                console.log(data);
            }, // missing comma
            // this runs if an error
            error: function (xhr, textStatus, errorThrown) {
                // show error
                console.log(errorThrown);
            }
        });
    });
}); // missing close block

答案 1 :(得分:2)

您在,处理程序函数后缺少逗号(success):

success: function (data){
    console.log(data);
}, // < here
error: function (xhr, textStatus, errorThrown) {
    console.log(errorThrown);
}