Karl White
Karl White

Reputation: 497

Alternative to $.load() not using AJAX

I am developing a webapp that is fully utilizing HTML5 Offline/Application Cache, which works really well except for one sticking point...

I use the $.load() function to load content when switching between pages. The files I'm loading are files on the same server, however because $.load uses $.ajax internally, these files are not fetched from the AppCache (the call simply fails).

var newPage = $('#slider').append('<div id="'+name+'">');
$('#'+name).load(someurl, function() {
    // Display the loaded content

(Note: someurl represents a file that does already exist in the AppCache, but just isn't loaded using the above code)

Does anyone know of an alternative to $.load that I can use to read .html files that contain javascript that will work when offline?

Ideally, this would be a simply drop in replacement for $.load, to load content from one file into a node.

Upvotes: 1

Views: 407

Answers (1)

Musa
Musa

Reputation: 97672

Try setting cache to true in ajax settings.

var newPage = $('#slider').append('<div id="'+name+'">');
$.ajaxSetup( {cache:true});
$('#'+name).load(someurl, function() {
    // Display the loaded content

Upvotes: 2

Related Questions