Home > Web Front-end > JS Tutorial > body text

The browser page goes back, how to re-run ajax

一个新手
Release: 2017-09-09 10:36:27
Original
1875 people have browsed it


Problem description:

When the browser page goes back, that is to say, you click the link to go to a page, and then click the back button to return to the previous page. The result Found that jQuery's ajax GET request is no longer executed? ? ?

Solution:

Disable ajax cache: $.ajaxSetup({ cache: false });

Tucao: In order to solve this problem on the Internet After reading for an hour, almost all the answers are nonsense. Finally found it at https://stackoverflow.com/questions/11508101/how-can-you-force-ajax-content-to-reload-when-a-user-presses-the-back-button-on in a deserted corner got the answer. The answer is just adding a line of code. . . . .

Example:

$(document).ready(function(){
    $.ajaxSetup({ cache: false }); // 仅添加这一句就可解决问题
    $.ajax({
        url: '/test_ajax',
        type: 'GET',
        dataType: 'json',
        success: function(data) {
           // 处理数据……
        },
        error: function() {
        }
    });
});
Copy after login

The above is the detailed content of The browser page goes back, how to re-run ajax. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!