一个ajax的问题:0x80004005 (NS_ERROR_FAILURE)
最近刚升级了firefox,以前的ajax程序是不报错的,可现在报了一个错。
Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLInputElement.selectionStart]
[在此错误处中断]
Filtered chrome url chrome://livemargins/content/appintent.js
不知为何,请大家帮忙看看
咸鱼型杏子茶
12 years ago
Answers
这是因为firefox安全性强,不允许跨域调用。
Firefox 要取消XMLHttpRequest的跨域限制的话,
第一是从 about:config 里设置 signed.applets.codebase_principal_support = true; (地址栏输入about:config 即可进行firefox设置)
第二就是在open的代码函数前加入类似如下的代码:
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
alert("Permission UniversalBrowserRead denied.");
}
<script type="text/javascript" language="javascript">
// Error: uncaught exception: Permission denied to call method XMLHttpRequest.open
var http_request = false;
function makeRequest(url, parameters) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
alert("Permission UniversalBrowserRead denied.");
}
http_request = false;
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url + parameters, true);
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var string = http_request.responseText;
alert(string);
} else {
alert('There was a problem with the request.');
}
}
}
function updateweather() {
makeRequest('http://www.abc.com/auto/rss_full/global/stations/16239.xml', '');
}
</script>
南回归线以北
answered 12 years ago