Home >Web Front-end >JS Tutorial >How to Prevent Browser Caching for AJAX Results in jQuery?

How to Prevent Browser Caching for AJAX Results in jQuery?

Susan Sarandon
Susan SarandonOriginal
2024-11-20 14:35:17407browse

How to Prevent Browser Caching for AJAX Results in jQuery?

Preventing Browser Caching for AJAX Results

When loading dynamic content via AJAX using jQuery's $.get(), you may encounter browser caching, leading to outdated data being displayed.

To resolve this, adding a random query string parameter, such as the current timestamp, has been commonly used. However, there is a more elegant approach.

By adding the following code snippet, you can globally disable AJAX result caching regardless of the jQuery method used:

$.ajaxSetup({ cache: false });

This setting effectively instructs the browser not to cache future AJAX requests, ensuring that you always retrieve the latest content.

The above is the detailed content of How to Prevent Browser Caching for AJAX Results in jQuery?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn