View Full Version : content will not load on web server but will load on local server
gylim78
07-13-2010, 04:14 PM
Hi all,
I have a site with Ajax content that is dynamically loaded. I store the product to be loaded on the URL using a #product_id=xxx. The page then uses a window.onload function to call a Ajax function to load the neccessary info about the product.
The problem I have now is this.
1. If I click on a link that links to that page .. eg. product.php#product_id=1 ... It works
2. However, if I refresh or manually type in the URL .. it does not work.
3. This problem is present in chrome and firefox but surprisingly not in IE6.
BUT, when I was developing the page on my localhost server. It works. I was developing using a apache server as well as MAMP on a mac. They both work.
Any reason that the content will load on a local server but not on a remote server ? btw ... my hosting compay is bluehost.
djr33
07-13-2010, 05:49 PM
Can you post a link? There could be a lot of reasons.
The general reason here is likely something related to the security issues associated with ajax, but beyond that it's hard to guess. I'm not particularly experienced with this sort of problem, but others here will probably know better. Either way, it'll help to see the site to figure out what's wrong.
In general, relative paths will be best for ajax due to security restrictions. See if that helps. That's my only guess at this point.
And if you've changed any of the URLs to external sites, that may also be the problem. But if you haven't changed your code, then that's not relevant.
gylim78
07-14-2010, 02:07 AM
All pages loaded are not from external site. Everything loaded is from the same server.
The site is at http://www.themagictouch.com.sg/touch-print/gift_products/
If you load that page the first time ... everything will load. But when you hit refresh, the content will not load.
Is there a difference between a link to a page and a refresh of the page ?
bluewalrus
07-14-2010, 02:29 AM
You have an error
ajaxpage(Object { name="url"}, Object { name="containerid"}, Object { name="hash"})ajaxcontent.js (line 36)
CheckForHash()ajax_history.js (line 24)
ajax_history.js()ajax_history.js (line 35)
[Break on this error] document.getElementById(containerid).i...v>" //Display "fetching page message"
ajaxcontent.js (line 36)
Not sure if that will resolve it or not.
gylim78
07-14-2010, 04:07 AM
Wierd ...
The line of code that seems to be in question is
document.getElementById(containerid).innerHTML="<div align=center><br><img src='../common/images/loading.gif'><p>Requesting content, please wait...</p></div>"; //Display "fetching page message"
This is just the html content to load to show the spinning wheel when the ajax content is loading...
From what I can see ...
The problem seems to be that when I refresh the page ... the javascript variable call current_hash is not being cleared.
At the top of my page, I declare
<script type='text/javascript'>var current_hash = "";</script>
then when the page loads, I check if the current_has has changed
function CheckForHash(){
if(document.location.hash){
var HashLocationName = document.location.hash;
HashLocationName = HashLocationName.replace("#","");
if (HashLocationName != current_hash){
current_hash = HashLocationName;
switch(current_hash)
{
case "print1":
url = "heat_transfer.php";
break;
case "print2":
url = "silkscreen.php";
break;
case "print3":
url = "embroidery.php";
break;
default:
url = "inline_view.php?" + HashLocationName;
}
ajaxpage(url, 'inline_view',document.location.hash)
}
}
else
{
ajaxpage('inline_view.php', 'inline_view','#0')
}
}
var HashCheckInterval = setInterval("CheckForHash()", 500);
window.onload = CheckForHash;
So by right when I refresh a page, the current_hash var should be cleared back to blank and the relevant ajax content should load in based on the hash set in the URL.
gylim78
07-19-2010, 10:04 AM
Hi All,
Still can't solve this issue. Now I have some new findings.
As the same as last time.
First time loading the page -> Ajax content loads properly.
Hit refresh ... Page loads but Ajax content does not load.
When I am running it on a localhost ( I have tried both MAMP on a mac and Apache on windows) It works perfectly !!
Now I used firebug to try and find the problem. I insert a breakpoint and slowly stepped through the code and guess what ? The Ajax content loaded !! So I can't find the bug !!
When I just hit refresh with no breakpoint, I get the message on the chrome javascript console
"Uncaught TypeError: Cannot set property 'innerHTML' of null"
The Line of code that is giving the error is
document.getElementById(containerid).innerHTML="<div align=center><br><img src='../common/images/loading.gif'><p>Requesting content, please wait ... </p></div>"
I really don't see how null could ever come up in this line of code ??
Could anyone help ?
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.