Reputation: 1734
This problem has been killing me!
I have some jquery which will always throw this error to the console:
Uncaught SyntaxError: Unexpected token .
from the line with the $.ajax() function call in it.
$('#send').click(function(){
$("#form").submit();
});
$("#form").submit({
$.ajax({
url: "../php/mailForm.php",
type:"POST",
data:$("#form").serialize(),
complete:function(){
$('#email').val("");
$('#subject').val("");
$('#message').val("");
$('#successMsg').removeClass("hidden");
}
});
return false;
});
Here is how I load both jquery and this javascript file.
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="../js/contact.js"></script>
(in that order)
Does anyone have any clue as to what's going on???
Upvotes: 0
Views: 503
Reputation: 59232
You should wrap them in a anonymous function function(){}
, the same way you did for .click()
:
$('#send').click(function(){
$("#form").submit();
});
$("#form").submit(function(){
$.ajax({
url: "../php/mailForm.php",
type:"POST",
data:$("#form").serialize(),
complete:function(){
$('#email').val("");
$('#subject').val("");
$('#message').val("");
$('#successMsg').removeClass("hidden");
}
});
return false;
});
.submit()
expects a function callback. So wrap your code inside an anonymous function.
Upvotes: 1