/    Sign up×
Community /Pin to ProfileBookmark

Access Denied

I am going to put together a program to parse an xml file using Javascript and am having problems with IE. Other browsers are fine with the start below, but IE7 is giving me the error “Access is denied” on the line starting with xmlHttp.open. IE6 is fine, and IE8 is not displaying the document.write text, so I am assuming that the error displayed in IE7 is happening.

The code I am using is below.

[INDENT][FONT=”Courier New”]<html>
<body>
<script type=”text/javascript”>
var xmlHttp = false;
try {
xmlHttp = new XMLHttpRequest();
} catch (TryMicrosoft) {
try {
xmlHttp = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (TryOtherMicrosoft) {
try {
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (ItFailed) {
xmlHttp = false;
}
}
}

xmlHttp.open(“GET”,”test.xml”,false);
xmlHttp.send(“”);
xmlDoc = xmlHttp.responseXML;

document.write(“Document loaded.”);

</script>
</body>
</html>[/FONT][/INDENT]

I am using IE Tester for my testing of IE.

Am I doing something wrong that is not allowing this work in IE or is it a browser setting? If it is the latter then I will not be able to write the routine, as it would not be appropriate to ask a visitor to change a setting just to be able to run the page. I’m thinking that there must be some way of doing this so that IE doesn’t get in the way.

Thanks for the help.

george

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 29.2010 — Usually you should check before some of the request object's properties, such as : [B]readyState[/B] and [B]status[/B]. [B]onreadystatechange[/B] would be also a better property/method to use when starting a request.

AJAX:

http://www.w3schools.com/Ajax/Default.Asp
Copy linkTweet thisAlerts:
@GLSmythauthorMar 30.2010 — Wouldn't that be the case if the third parameter of the open() method were "true", or is IE different in that respect, which would be why this works in other browsers but errors on that line in IE?

Thanks -

george
Copy linkTweet thisAlerts:
@GLSmythauthorMar 30.2010 — I went ahead and changed the third parameter of the open() method to true:

xmlHttp.onreadystatechange = function() {

if (xmlHttp.readyState == 4) {

alert("Ready state passed.");

}

}

xmlHttp.open("get", "test.xml", true);

xmlHttp.send("");

xmlDoc = xmlHttp.responseXML;

This works in Firefox but gives an Access Denied error in Internet Explorer.

Thanks -

george
Copy linkTweet thisAlerts:
@KorMar 30.2010 — usually the whole AJAX request is encapsulated [I]within a function[/I] which is to be called by a certain event
×

Success!

Help @GLSmyth 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,
)...