/    Sign up×
Community /Pin to ProfileBookmark

Works in Safari/FF but not IE

Hi There

I’m working on a simple ajax switcher to load different content into a div. It works great in Firefox and Safari, but raises two errors in Internet Explorer. I’d really appreciate anyone’s input into what might be wrong…

Javascript/AJAX

[CODE]<!–
var loadedobjects=””
var rootdomain=”http://”+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject(“Msxml2.XMLHTTP”)
}
catch (e){
try{
page_request = new ActiveXObject(“Microsoft.XMLHTTP”)
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open(‘GET’, url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf(“http”)==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=””
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(“.js”)!=-1){ //If object is a js file
fileref=document.createElement(‘script’)
fileref.setAttribute(“type”,”text/javascript”);
fileref.setAttribute(“src”, file);
}
else if (file.indexOf(“.css”)!=-1){ //If object is a css file
fileref=document.createElement(“link”)
fileref.setAttribute(“rel”, “stylesheet”);
fileref.setAttribute(“type”, “text/css”);
fileref.setAttribute(“href”, file);
}
}
if (fileref!=””){
document.getElementsByTagName(“head”).item(0).appendChild(fileref)
loadedobjects+=file+” ” //Remember this object as being already added to page
}
}
}
–>

<!–
function homepagethings(){
ajaxpage(‘includes/homepage/recentimages.php’, ‘recentimagesmostpop’)
ajaxpage(‘includes/homepage/welcome.php’, ‘newswelcomecontainer’)
}
–>[/CODE]

HTML Code to create the tabs

[CODE]<div class=”homesearch”>

<a href=”javascript:ajaxpage(‘includes/homepage/recentimages.php’, ‘recentimagesmostpop’);”>
<img src=”resources/images/recentlyadded.gif” border=”0″ alt=”Recently Added Stock Photography” /></a>

<a href=”javascript:ajaxpage(‘includes/homepage/mostpopular.php’, ‘recentimagesmostpop’);”>
<img src=”resources/images/mostpopular.gif” border=”0″ alt=”Most Popular Stock Photos” /></a>

<a href=”http://feeds.feedburner.com/ourstockrecent”><img src=”resources/images/rss.gif” border=”0″ alt=”Recent Images RSS Feed” /></a>

<div id=”scrollsearch”>

<div id=”recentimagesmostpop”>

</div>

</div>
</div>[/CODE]

Thankyou! I’d really appreciate any help.

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@dappleyardauthorMar 25.2006 — Anyone got an idea? I'd be incredibly grateful for any help
Copy linkTweet thisAlerts:
@felgallMar 25.2006 — Maybe there is a problem with the earliest two of the ActiveX objects for AJAX. Most people should be using browsers that support one of the three more recent versions by now.
Copy linkTweet thisAlerts:
@dappleyardauthorMar 25.2006 — Right... i'm with you. Any ideas how i can get around the problem? Or implement it in a different way?

Thanks a lot
Copy linkTweet thisAlerts:
@FangMar 25.2006 — The first script src is corrupted in both browsers.

The ajax.js script is full of commenting strings ??
Copy linkTweet thisAlerts:
@dappleyardauthorMar 25.2006 — Fang,

That's interesting... Just took at look at the source code in notepad and noticed that is the case. Development is done on a Mac primarily, so hadn't noticed. However, I think I've fixed the formatting but the error is still appearing.

Any ideas? - Fang, I really appreciate the advice. This has been bugging me for ages.
Copy linkTweet thisAlerts:
@FangMar 25.2006 — IE and FF give:&lt;script src="/mint/?js" type="text/javascript"&gt;&lt;/script&gt;
Copy linkTweet thisAlerts:
@dappleyardauthorMar 25.2006 — Forgive me if I'm being ignorant, but is there anything wrong with that? ?
Copy linkTweet thisAlerts:
@dappleyardauthorMar 26.2006 — Does anyone know what's wrong with that line of code Fang drew my attention to?

Thanks!
Copy linkTweet thisAlerts:
@dappleyardauthorMar 26.2006 — Sorted. I re-created all the code using the details found at the following link. Great article.

http://godbit.com/article/axah-crawl-before-you-ajax
×

Success!

Help @dappleyard spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...