0

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???

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.