Jquery Ajax Beforesend Example - Jquery

How to use beforesend concept in ajax jquery?

Snippet Code


  
Rate this page :
  [ 0 votes]

This jquery ajax beforesend code allows you to stop ajax call before sending an ajax request through abort method. Here the abort()method is used to stop the ajax request.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type='text/javascript'> function ajax_call() { var test = $.ajax({ url : 'ajax-demo.php', type: 'POST', dataType: 'script', beforeSend : function(data){ if(1 == 1) //just an example { alert('Test beforeSend'); data.abort(); return false; } }, complete: function(){ console.log('DONE'); } }); } </script> <input type='button' value='Click Here!' onclick='ajax_call()'>

Tags


Ask Questions

Ask Question