PDA

View Full Version : Resolved Loading a Page



Deadweight
05-12-2015, 12:23 AM
So I have a few questions. The first is I am trying to load a page into a website and I can get it to work doing this:



$(document).on({
click:function(){
$(this).hide()
loadObject()
//setInterval(loadObj, 3000);
}
},'#loadItem')

function loadObject(){
$.get( "../Gabe%20and%20Our%20Website/index.html", function( data ) {
var area = '../Gabe%20and%20Our%20Website/'
var head_start = data.indexOf('</title>')+("</title".length+1)
var head_end = data.indexOf('</head>')
var head_html = data.substring(head_start, head_end);

head_html = head_html.replace(/src="+/g, 'src="'+area+'');
head_html = head_html.replace(/href="+/g, 'href="'+area+'');

var body_start = data.indexOf('<body>')+('<body>'.length+1)
var body_end = data.indexOf('</body>')

var body_html = data.substring(body_start, body_end)

$( "#loader" ).html(head_html+body_html);

});
}


First problem is that I need to keep reloading the page; however, it saves the page. I am assuming it is from the cache. Is there a way to stop that?

Also I cant get my setInterval to work once i click on #loadItem. Any ideas?

Deadweight
05-12-2015, 12:29 AM
Update:
I now use this:

$.ajax({
url:'../Gabe%20and%20Our%20Website/index.html',
cache: false,
dataType:"html",
success: function(data){
var area = '../Gabe%20and%20Our%20Website/'
var head_start = data.indexOf('</title>')+("</title".length+1)
var head_end = data.indexOf('</head>')
var head_html = data.substring(head_start, head_end);

head_html = head_html.replace(/src="+/g, 'src="'+area+'');
head_html = head_html.replace(/href="+/g, 'href="'+area+'');

var body_start = data.indexOf('<body>')+('<body>'.length+1)
var body_end = data.indexOf('</body>')

var body_html = data.substring(body_start, body_end)

$( "#loader" ).html(head_html+body_html);
}
})

But i cant get the setInterval to work. (when not commented out)

Deadweight
05-12-2015, 12:33 AM
Nevermind i was jumping ahead of myself i got it:


setInterval(function () {loadObject()}, 5000);