你好我使用jQuery的.load()方法加载页面。 在页面完全加载到Firefox的,但是当我在谷歌浏览器打开该网页是不会加载。
你们是否有一些解决方案。
<脚本>
VAR XMLHTTP;
传播initAjax(){
尝试 {
XMLHTTP =新XMLHtt prequest(); // Firefox,歌剧8.0+,Safari浏览器
}赶上(五){
尝试 {
XMLHTTP =新的ActiveXObject(MSXML2.XMLHTTP); // IE浏览器
}赶上(五){
尝试 {
XMLHTTP =新的ActiveXObject(Microsoft.XMLHTTP);
}赶上(五){
警报(没有AJAX!?);
返回false;
}
}
}
xmlHttp.onreadystatechange =功能(){
如果(xmlHttp.readyState == 4){
的document.getElementById('main_container)的innerHTML = xmlHttp.responseText。
}
}
}
功能updateAjax(我的空间){
VAR T =我的页面;
//警报(T);
如果(T ==)
{
//警报(盈通);
}
其他
{
xmlHttp.open(GET,T,真正的);
xmlHttp.send(空);
}
}
在window.onload =功能(){
initAjax();
}
< / SCRIPT>
< DIV ID =main_container的风格=的位置是:相对;>
< / DIV>
<脚本的src =../ JS / jquery.min.js>< / SCRIPT>
<脚本的src =../ JS / bootstrap.min.js>< / SCRIPT>
<脚本的src =../ JS / docs.min.js>< / SCRIPT>
<脚本的src =../ JS / jRating.jquery.js>< / SCRIPT>
<脚本类型=文/ JavaScript的>
$(#main_container)的负载(home.html做为)。
< / SCRIPT>
解决方案
这个问题就是这样 .load()
本地文件出于安全原因阻止Chrome浏览器。如果你是它的工作原理服务器,因为使用它的所有的文件来自同一个地方起源。
要在本地启用一个工作版本,请尝试:
在Mac OS X中,相当Chrome浏览器,在终端中输入:
/应用/谷歌\ Chrome.app /内容/ MacOS的/谷歌\铬--allow文件存取的档案
在Windows中,相当Chrome浏览器,在命令提示符下输入:
的chrome.exe --allow文件存取的档案
(也许你实际上必须有路径...我不这么认为。如果是这样,你必须自己找到它。)
在Linux中,相当Chrome浏览器,输入这样的事情到终端:
的/ usr / bin中/谷歌铬--allow文件存取的档案
Hi I am loading a page using jquery .load() method. the page is loaded perfectly on the firefox but it isn't load when I am opening the page on the google chrome.
Do you guys have some solution.
<script>
var xmlHttp;
function initAjax() {
try {
xmlHttp = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
} catch(e) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
} catch(e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
alert("No AJAX!?");
return false;
}
}
}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4) {
document.getElementById('main_container').innerHTML = xmlHttp.responseText;
}
}
}
function updateAjax(mypage) {
var t=mypage;
//alert(t);
if(t=="")
{
//alert("Welldone");
}
else
{
xmlHttp.open("GET", t, true);
xmlHttp.send(null);
}
}
window.onload = function() {
initAjax();
}
</script>
<div id="main_container" style="position: relative;">
</div>
<script src="../js/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/docs.min.js"></script>
<script src="../js/jRating.jquery.js"></script>
<script type="text/javascript">
$("#main_container").load("home.html");
</script>
解决方案
The issue is just that .load()
for local files is blocked by Chrome for security reasons. If you are using it on a server it works, given that all of the files originate from the same place.
To enable a working version locally, try:
In Mac OS X, quite Chrome, enter in Terminal:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files
In Windows, quite Chrome, enter in Command Prompt:
chrome.exe --allow-file-access-from-files
(Maybe you actually have to have the path... I don't think so. If so, you'll have to find it yourself.)
In Linux, quite Chrome, enter something like this into the terminal:
/usr/bin/google-chrome --allow-file-access-from-files