admin管理员组文章数量:1023213
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")
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")
版权声明:本文标题:javascript - Access is denied when try to read a local xml file using ajax request on IE only - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745571848a2156783.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论