如果本地的javascript要访问远程的内容,在firefox里因为安全性的考虑,缺省的话是不能访问的。在tools ->error console里会出来一下类似:
security error, file at ... may not load data from ...的提示。
参考http://www.mozilla.org/projects/security/components/jssec.html 里讲的,在我们的javascript里增加一句: netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");
这时执行的时候firefox是弹出一个对话框,这里点确定,就可以成功调用了。
附我的一段code:
function ajaxdecode() { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead"); xmlhttp.open("GET", 'http://xx.xx.xx.xx/code.php?type=' + $('type').value + "&text=" + $('text').value , true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { document.getElementById('result').innerHTML = xmlhttp.responseText; } } xmlhttp.send(null ); return false; }