Guest User

Untitled

a guest
Sep 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. var $ajaxScript = 'scripts/ajax.php'; // controller-script that handles all ajax script request
  2. /**
  3. * ajax wrapper
  4. * $_POST array of form posts
  5. */
  6. function submitAjax($_POST){
  7. ajaxObj = $.ajax({url:$ajaxScript, data:$_POST, type:'POST', dataType:'json' });
  8. return ajaxObj;
  9. }
  10.  
  11. $(function(){
  12. $("form.ajax").submit(function(e){
  13. e.preventDefault();
  14. submitAjax($(this).serialize())
  15. .done(function(data,statusText,jqXHR){
  16. $(this).prepend('<div class="notice"><p class="icon">'+data['msg']+'</p></div>'); // *-- this triggers a "TypeError"
  17. console.log('done : '+statusText); // <-- this alone doesn't throw any error
  18. })
  19. .fail(function(){
  20. console.log('fail');
  21. })
  22. .always(function(){
  23. console.log('always');
  24. });
  25. });
  26. });
Add Comment
Please, Sign In to add comment