javascript Ajax 语法:未捕获的语法错误:意外的标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10741697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:52:51  来源:igfitidea点击:

Ajax syntax : Uncaught SyntaxError: Unexpected identifier

javascriptjquery

提问by Yahoo

I am getting this Uncaught SyntaxError: Unexpected identifier error , Why ? I think i have used the syntax properly ?

我收到这个 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>');
        }

    }
});?

回答by Naftali aka Neal

You left off the comma after the data

你在后面留下了逗号 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) {

回答by Denys Séguret

A comma is missing before "success"

前面少了一个逗号 "success"

回答by epascarello

You are sending up strings with the jQuery code and you are mising a comma

您正在使用 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

with it fixed it should be

固定它应该是

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

回答by JerseyMike

You seem to be missing a comma between your closing curly brace and success:.

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