.

How to Intecept a jquery.ajax call with confirm () How to Intecept a jquery.ajax call with confirm ()

How to Intecept a jquery.ajax call with confirm ()


 BY:  CodingTips [  Updated on:Dec-30-2019]    
   Reading Time: About 1 minutes




 

Ajax is a set of web development techniques using many web technologies on the client side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously without interfering with the display and behavior of the existing page.

Below code helps you to give the condition, before running the ajax code. This is widely used to prevent the existing content to not get deleted.

$('.removeItem').click(function (event)
{ if (confirm('Are you sure you want to delete this?'))
{ $.ajax({ url: 'myUrl', type: "POST", data:
{ // data stuff here }, success: function ()
{ // does some stuff here... } }); } });

 

You can use the above code for all types of deleting options. If you would like to create a post based system including the delete button, learn how to intercept a jquery.ajax call with confirm()

 


Leave a Comment


Login to post a public Comment

Comments 3.


Daily Motivation
4 years ago

I've actually implemented this on my website.

Thanks for sharing this tip.

Facts And Fun
5 years ago

Very useful thanks for sharing this..

gadgets tech
5 years ago

Great stuff thank you