I am trying to read a local file forms.xml
from an single html page (not an application ).
Javascript code :
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","forms.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
}
I think my code is correct because it doing good in firefox
and crome
but in IE its saying
SCRIPT5: Access is denied.
on line xmlhttp.open("GET","forms.xml",false);
Now i have read some post concerning this issue they all give different solution and some say its a problem in IE 9 but i am using 10.0.9200
Possible explanation and solution please.
I am trying to read a local file forms.xml
from an single html page (not an application ).
Javascript code :
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","forms.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
}
I think my code is correct because it doing good in firefox
and crome
but in IE its saying
SCRIPT5: Access is denied.
on line xmlhttp.open("GET","forms.xml",false);
Now i have read some post concerning this issue they all give different solution and some say its a problem in IE 9 but i am using 10.0.9200
Possible explanation and solution please.
Share Improve this question asked Jan 25, 2015 at 10:26 SaifSaif 7,0728 gold badges43 silver badges62 bronze badges 7- Is this running on Windows 8 by any chance? – haxtbh Commented Jan 25, 2015 at 10:30
- no the os is Windows 7 Professional (SP1) 64 bit. – Saif Commented Jan 25, 2015 at 10:31
- Are you running locally or using a webserver? – haxtbh Commented Jan 25, 2015 at 10:32
- locally and not even in a local server its just a single html file opened in browser. – Saif Commented Jan 25, 2015 at 10:33
- In IE AJAX works with http(s) protocol only. – Teemu Commented Jan 25, 2015 at 10:45
3 Answers
Reset to default 1This is an issue with cross domain requests. XMLHttprequest needs to be called on the same domain only and running via a http request. Running your page locally with no server will cause the access denied error in IE (as well as most other browsers)
If you are just testing you can try overriding a setting in IE to see if it helps.
You can enable cross-domain on IE by going into Internet Options -> Security Settings ->Custom level and enabling "Access data sources across domains".
This piece of code is working on any older browser starting from IE5
try{
xmlhttp = new XMLHttpRequest();
}catch(e){
try {
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
catch(e){
try {
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
}
catch(e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
alert("XMLHTTP Not Supported On Your Browser");
}
}
}
}
use xmlhttp = new ActiveXObject("MSXML2.XMLHTTP")