2015-10-06 68 views
0

我得到这个语法错误,因为我错过了}有人可以告诉我我可能忽略了什么......这说行25,但我没看到它。语法错误Jquery AJAX调用

错误

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); 
     } 
    }); 
}); 

回答

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 
+0

你试过我的代码吗?它仍然会抛出错误。我指出了两个错误。 – 2015-10-06 17:58:34

+0

@Vicki我正在查看它。 – 2015-10-06 18:01:09

+0

@Vicki你可以通过检查F12开发工具的Console Tab来显示AJAX调用的输出吗? – 2015-10-06 18:03:18

2

你的success处理函数后缺少一个逗号(,):

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

@Vicki不同的错误,不同的问题。 –