javascript - JQuery/JS Ajax function not recognized -


this problem has been killing me!

i have jquery throw error console:

uncaught syntaxerror: unexpected token .  

from line $.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 how load both jquery , javascript file.

<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script> <script src="../js/contact.js"></script> 

(in order)

does have clue what's going on???

you should wrap them in anonymous function function(){}, same way did .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 function callback. wrap code inside anonymous function.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -