Missing { after argument list
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:
- The extra semicolon.
show()
syntax.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.")
精彩评论