PDA

View Full Version : HOW TO: View "Dynamic Ajax Content" locally (offline) in IE7



Athrill
05-23-2007, 07:37 AM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem: When previewing content locally in IE7 using the "Dynamic Ajax Content" script, you get an "Access Denied" error and the dynamic pages doesn't appear, but works remotely from a web server.

This issue is discussed in several threads, e.g. http://www.dynamicdrive.com/forums/showthread.php?t=15642&highlight=Dynamic+Ajax+Content

I was able to append the javascript so one can now work and preview changes offline/locally. Not that i'm boasting by any means, just that after looking for a solution to this and not finding an easy one, I decided to try and make a workaround of my own.

Please let me know if this is helpful to anyone or if it creates any problems.


~peace,
Athrill

++++++++++

THE HOW TO:
Assuming you are using the cut-and-paste Dynamic Ajax Content script (http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm) from "Step 1" and haven't made any heavy modifications, this should work fine, although being a somewhat novice coder, I don't guarantee this modification ;)

1. Replace the code between (keeping these two lines in tact) the 5th variable from the top of the script
var page_request = false and the first XMLHttpRequest
if (window.XMLHttpRequest) // if Mozilla, Safari etc with the "UPDATED CODE" below.

UPDATED CODE:

if (rootdomain) // if accessing remote server (not locally)
if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else // if accessing locally (not remote server)

ddadmin
05-23-2007, 08:53 AM
Thanks for sharing. The issue can be explained a lot quicker though. Basically, IE7 supports both window.XMLHttpRequest and the old window.ActiveXObject objects for making Ajax requests. The former is also used by Firefox, Opera etc, though in IE 7, offline Ajax requests isn't allowed using it. The altenative is to still use window.ActiveXObject in IE7 if you really have to run your Ajax code offline, though Microsoft has said they strongly encourage using the new object instead due to various improvements in it.


if (window.XMLHttpRequest) // if Mozilla, Safari and IE 7 now etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE

Athrill
05-23-2007, 09:09 AM
hi ddadmin and thanks for the reply.

does the code you show allow one to run the Dynamic Ajax Content script/code both offline and online, without having to change the script each time (for functioning offline or online previews)?

this is the problem - more of an annoyance - that i was having before modifying the original script - getting it to work locally and remotely, without having to make changes to the script.

is ther any eaiser way of doing this?

thanks for your insight, i'm still at the beginning stages of learning Ajax.

ddadmin
05-23-2007, 11:36 AM
Actually, the code I posted merely shows why the Dynamic Ajax script doesn't work in IE7 offline- because IE7 picks up on and uses the window.XMLHttpRequest object like Firefox does. You can try forcing IE to not use this object by doing something like:


if (window.XMLHttpRequest && !document.all) // if Mozilla, Safari, etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE

savezvous
09-25-2007, 10:27 PM
Thanks, Athrill! This is just the solution I was looking for. I'm building a CD that needs to function offline on all browsers and I wanted to use this script. Now I can.