Home > Web Front-end > JS Tutorial > Ajax get request cache processing solution

Ajax get request cache processing solution

亚连
Release: 2018-05-25 14:01:57
Original
2224 people have browsed it

This article mainly introduces the caching processing solution for ajax get request, and analyzes the four common solutions in detail, which is of great practical value. Friends in need can refer to it

The examples in this article are described A solution to cache processing during ajax get request. Share it with everyone for your reference. The specific analysis is as follows:

Many times when the Ajax get method is called, the correct data cannot be obtained in time due to caching. Here is an analysis of the method to solve this problem:

1 . Add a random number after the url, such as:

http://www.test.com?a=a&b=b&r=Math.random();

2. After the url Add timestamp:

var t = new Date().getTime();
http://www.test.com?a=a&b=b&t=t

3. Use the setRequestHeader function of the XMLHttpRequest object to set the value of If-Modified-Since to 0, such as

xmlHttp.setRequestHeader('If-Modified-Since', 0);

Here you need to understand If The meaning of -Modified-Since

4. Use the header function of php

header('Cache-Control:no-cache, must-revalidate');

Set no Using cache

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Implement drop-down box linkage display data based on Ajax

Ajax verification form example with prompt

Ajax implementation of pop-up non-refresh city selection function code

##

The above is the detailed content of Ajax get request cache processing solution. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template