开发者

Missing { after argument list

开发者 https://www.devze.com 2023-03-20 15:29 出处:网络
This is missing a semi colon or curly bracket or something and I can\'t find out where or how. Any suggestions on how to debug this sort of issue would help. I added one on the line firebug told me a

This is missing a semi colon or curly bracket or something and I can't find out where or how.

Any suggestions on how to debug this sort of issue would help. I added one on the line firebug told me and it still didn't work nor make sense.

$(document).ready(function () {
            $('#go').click(function () {
                $.ajax({
                    type: 'POST',
                    data: $('#newsletter').serialize(),
                    url: $('#newsletter').attr('action'),
                    success: function()
                    {
                    $('#thankYou').show(1000,setTimeout(

                    function(){
                    $('#thankYou').hide()
                    })

                    ,3000);


                    };
                });
                 return false;
            });

        });

it is still showing a syntax error with this

function()
                    {
                    $('#thankYou').show(1000,setTimeout(

                    function(){
                    $('#thankYou').hide()
                    })

                    ,3000);


                 开发者_运维知识库   }


You should do more nesting on those functions, it may help you figure it out in the future. Here is the code more indented:

$(document).ready(function() {
    $('#go').click(function() {
        $.ajax({
            type: 'POST',
            data: $('#newsletter').serialize(),
            url: $('#newsletter').attr('action'),
            success: function() {
                $('#thankYou').show(1000, setTimeout(function() {
                    $('#thankYou').hide();
                }), 3000);
            };
        });
        return false;
    });
});

The problem is the ';' after the success function declaration.


Here:

                    ,3000);


                }; //<-- that should not have a semicolon


It looks like 3 problems:

  1. The extra semicolon.
  2. show() syntax.
  3. setTimeout() syntax.

This should work; See it in action at jsFiddle. :

$(document).ready ( function () {
    $('#go').click ( function () {
        $.ajax ( {
            type:       'POST',
            data:       $('#newsletter').serialize (),
            url:        $('#newsletter').attr ('action'),
            success:    function () {
                            $('#thankYou').show (
                                1000, 
                                function () {
                                    setTimeout ( function() { $('#thankYou').hide(); }, 3000);
                                }
                            );
                        }
        } );
        return false;
    } );
} )


PS: For just showing and hiding, jQuery provides:

success:    function () {
                $('#thankYou').show (400).delay (2500). hide (400);
            }

("We don't need no stinking setTimeout.")

0

精彩评论

暂无评论...
验证码 换一张
取 消