语法错误:缺少}属性列表后[打破此错误]});

时间:2013-06-21 17:23:02

标签: jquery

有人可以用这种语法帮助我吗? Firebug继续告诉我错误没有我试过的

$(document).ready(function () {
    $(".custompage").click(function () {
        var Splitter = (this.id).split("-");
        var thepage = Splitter[1];
        $("#myblock").slideUp();
        $.ajax({
            type: "POST",
            url: "userpagesajax.php",
            data: {
                pageid: thepage,
                siteid: "' . $siteid . '"
            },
            success: function (Response) {
                $("#myblock").slideDown(Response);
            });
        });
    })

3 个答案:

答案 0 :(得分:2)

更正语法 -

$(document).ready(function () {
    $(".custompage").click(function () {
        var Splitter = (this.id).split("-");
        var thepage = Splitter[1];
        $("#myblock").slideUp();
        $.ajax({
            type: "POST",
            url: "userpagesajax.php",
            data: {
                pageid: thepage,
                siteid: "' . $siteid . '"
            },
            success: function (Response) {
                $("#myblock").slideDown(Response);
            } // you had an extra );
        });
    });
}); // you were not closing .ready

答案 1 :(得分:1)

您需要使用}

关闭ajax选项
 $.ajax({
            type: "POST",
            url: "userpagesajax.php",
            data: {
                pageid: thepage,
                siteid: "' . $siteid . '"
            },
            success: function (Response) {
                $("#myblock").slideDown(Response);
            } // <-- Success function block closed here
        }); //<-- Ajax options closed here along with ajax method brackets.

最简单的方法是使用浏览器本身,点击显示错误的控制台,它会将您带到导致错误的行,从而找到线索。

$(document).ready(function () {
    $(".custompage").click(function () {
        var Splitter = (this.id).split("-");
        var thepage = Splitter[1];
        $("#myblock").slideUp();
        $.ajax({
            type: "POST",
            url: "userpagesajax.php",
            data: {
                pageid: thepage,
                siteid: "' . $siteid . '"
            },
            success: function (Response) {
                $("#myblock").slideDown(Response);
            }
        });
    });
});

答案 2 :(得分:0)

    $(document).ready(function () {
    $(".custompage").click(function () {
        var Splitter = (this.id).split("-");
        var thepage = Splitter[1];
        $("#myblock").slideUp();
        $.ajax({
            type: "POST",
            url: "userpagesajax.php",
            data: {
                pageid: thepage,
                siteid: "' . $siteid . '"
            },
            success: function (Response) {
                $("#myblock").slideDown(Response);
            }
        });
    });
});

这应该有效。只是放错了括号和括号。

顺便说一句,将来使用本网站。每当我有一个我无法自己发现的小虫时,我就会使用它。

http://jsfiddle.net/

你可以点击JSHint,它会突出显示错误的位置。它还会突出显示括号和括号为绿色或红色,具体取决于它们是否关闭。