How to prevent caching from jquery ajax?

by elisha_langworth , in category: Third Party Scripts , 6 months ago

How to prevent caching from jquery ajax?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raven_corwin , 6 months ago

@elisha_langworth 

To prevent caching in jQuery AJAX requests, you can add a cache parameter to the AJAX request and set it to false. This will append a timestamp to the request URL, ensuring that each request is unique and prevents caching. Here is an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$.ajax({
  url: 'example.com/api',
  method: 'GET',
  cache: false,
  success: function(response) {
    // Handle response
  },
  error: function(error){
    // Handle error
  }
});


By setting cache to false, you can prevent caching of AJAX requests and ensure that the data is always up-to-date.

Related Threads:

How to validate a laravel form using jquery ajax?
How to call ajax in jquery in laravel?
How to disable ajax caching?
How to send an ajax request using jquery in laravel?
How to prevent caching in angular?
How to prevent html5 page from caching?