【问题标题】:Im getting a Syntax error in Jquery/Ajax code [closed]我在 Jquery/Ajax 代码中遇到语法错误 [关闭]
【发布时间】:2014-08-26 04:41:19
【问题描述】:

代码有错误 语法错误

    $(function(){
            $("#users").on("change", function(e){

               /* values from select statement and assigning to a variable*/
                var $filter = $("#users").val();

                $.ajax({
                   /*sending variable to the controller */
                    url: "finance/finance_transaction/",

                    data: {filter: $filter},/* variable */ 
                    dataType: "html" 

                    }).done(function(msg){

                    }).fail({});
             )}; /*syntax error points here */
        )};

它从 select 语句中获取值并将其发送到控制器

【问题讨论】:

  • 您遇到的错误是什么?
  • thnx 是括号错误

标签: php jquery ajax codeigniter


【解决方案1】:
$(function(){
    $("#users").on("change", function(e){
        // ...valid code, skipped... 
    )}; /*syntax error points here */
)}; 

大括号不匹配。与 HTML 标记一样,您先打开的标签必须最后关闭。最后两行应该是:

    });
});

【讨论】:

  • thnx i chnged nw im getting this error "Uncaught ReferenceError: $filer is not defined"
  • @Usuf 发布的代码中没有$filer 标识符。不过有$filter
【解决方案2】:

你的右括号会引起问题

$(function(){
            $("#users").on("change", function(e){

               /* values from select statement and assigning to a variable*/
                var $filter = $("#users").val();

                $.ajax({
                   /*sending variable to the controller */
                    url: "finance/finance_transaction/",

                    data: {filter: $filter},/* variable */ 
                    dataType: "html" 

                    }).done(function(msg){

                    }).fail({});
            }); /*corrected here */
        });   /*corrected here */

【讨论】:

  • 如果你能帮我解决这个错误 - “Uncaught ReferenceError: $filer is not defined”
  • 没有这样的变量,$filter。你要先定义它。
猜你喜欢
  • 1970-01-01
  • 2011-11-23
  • 2015-03-28
  • 2017-05-18
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 2011-12-14
  • 2018-12-17
相关资源
最近更新 更多