简体   繁体   中英

Read a txt file from jQuery (304 Not Modified)

I am trying to load a text file via a jQuery ajax call $.get the issue i am receiving is a 304 Not Modified in console.

I am trying to get the data from the text file which will be local to the document it is called from. In this instance the text file will just contain a single word master . The aim for loading the data is to call a global variable that will trigger certain events based on the text in the text file.

Here is the code in question:

var sv_settings;
$.get('settings.txt', function(data) {
    sv_settings = data;
});

What am i missing? Why is my browser returning 304 Not Modified ?

Try tricking the cache:

var sv_settings;
$.get('settings.txt?v='+Math.random(), function(data) {
    sv_settings = data;
});

This will make your browser think that settings.txt?v=0.234234 is a different file from settings.txt?v=0.111222 which we know is not the case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM