【问题标题】:Ajax syntax : Uncaught SyntaxError: Unexpected identifierAjax 语法:未捕获的 SyntaxError:意外的标识符
【发布时间】:2012-05-24 16:36:03
【问题描述】:

我收到这个 Uncaught SyntaxError: Unexpected identifier error ,为什么? 我想我已经正确使用了语法?

$.ajax({
    url: "loadcontent1.php",
    data: {
        lastid: '$(".postitem").size()',
        location: '$("#location").val()',
        rstatus: '$("#rstatus").val()',
        gender: '$("#gender").val()'
    }
    success: function(html) {
        Uncaught SyntaxError: Unexpected identifier
        if (html) {
            $("#contentwrapper").append(html);
            $('div#ajaxloader').hide();

            $("#contentwrapper").masonry('reload');
            FB.XFBML.parse();

        } else {
            $('div#ajaxloader').html('<center>No more Images.</center>');
        }

    }
});​

【问题讨论】:

  • 顺便说一句,您确定要在$(".postitem").size() 周围加上引号吗?
  • 没有“Ajax 语法”之类的东西。

标签: javascript jquery


【解决方案1】:

您在data 之后省略了逗号

$.ajax({
    url: "loadcontent1.php",
    data: {
        lastid: $(".postitem").size(),
        location: $("#location").val(),
        rstatus: $("#rstatus").val(),
        gender: $("#gender").val() // not strings!
    }//, comma here!
    success: function(html) {

【讨论】:

    【解决方案2】:

    您正在使用 jQuery 代码发送字符串,但您缺少逗号

    data: {
        lastid: '$(".postitem").size()',  <--no single quotes
        location: '$("#location").val()', <--no single quotes
        rstatus: '$("#rstatus").val()', <--no single quotes
        gender: '$("#gender").val()' <--no single quotes
    }  <--no comma
    

    它应该是固定的

    data: {
        lastid: $(".postitem").size(), 
        location: $("#location").val(),
        rstatus: $("#rstatus").val(),
        gender: $("#gender").val() 
    },
    

    【讨论】:

      【解决方案3】:

      您的右花括号和成功之间似乎缺少逗号:。

      【讨论】:

        【解决方案4】:

        "success"前缺少一个逗号

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-09-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多