最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ajax syntax : Uncaught SyntaxError: Unexpected identifier - Stack Overflow

programmeradmin2浏览0评论

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

$.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>');
        }

    }
});​

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

$.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>');
        }

    }
});​
Share Improve this question edited May 24, 2012 at 16:46 Felix Kling 816k180 gold badges1.1k silver badges1.2k bronze badges asked May 24, 2012 at 16:36 YahooYahoo 4,18718 gold badges64 silver badges85 bronze badges 2
  • 1 As an aside, are you sure you want quotes around $(".postitem").size() ? – Denys Séguret Commented May 24, 2012 at 16:40
  • There is no such thing as "Ajax syntax". – Felix Kling Commented May 24, 2012 at 16:47
Add a comment  | 

4 Answers 4

Reset to default 14

You left off the comma after the 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) {

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

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() 
},

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

A comma is missing before "success"

发布评论

评论列表(0)

  1. 暂无评论