2013-09-23 89 views
1

更新
我刚刚测试了链接到我的例子和...该死的事情的作品。我不相信?任何意见仍然欢迎。

我刚刚更新了我的浏览器,Chrome拒绝了我的(以前工作的)ajax调用包含html的简单文本文件。这是我目前的裸机代码:

var stringData = $.ajax({ url: 'digz/index/'+$(this).attr("id")+'.txt', async: false }).responseText; 
var $newItems = $(stringData); 
alert($newItems.filter('.element').length); // FF & IE OK but Chrome = '0' 
// there are few things here and I have tested with them rem'd out 
$('#container').isotope('insert', $newItems); // std. isotope form 

中的Chrome控制台给我:

Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. 
XMLHttpRequest cannot load [...file path/name... ] Origin null is not allowed by Access-Control-Allow-Origin. 

和指针jQuery中 - 在版本1.9.0

// Do send the request 
// This may raise an exception which is actually 
// handled in jQuery.ajax (so no try/catch here) 
xhr.send((s.hasContent && s.data) || null); 

周围线8472我在这里有一个精简版的项目:
Null return on Ajax

我认为ajax行是问题,需要修改。我尝试了很多替代排列,但有很多选择和我的经验是有限的。

+1

看看是否有帮助http://stackoverflow.com/a/10866062/1331430 –

+0

@FabrícioMatté - 感谢您的链接。您在我的保存和更新之间张贴。往上看。是的,我意识到我需要使用Chrome在服务器环境中运行本地版本。 FF&IE对当地的关系非常满意。我将尝试“--allow-file-access-from-files”并查看它是如何工作的。谢谢。使用localhost开发 – Arfa

回答

0

很可能您正在使用file:///方案打开文件。如果这样做,Chrome将不允许直接访问硬盘的文件。

正如我other answer提到,有它运行Chrome使用此标志的解决方法:您使用本地计算机计划严重的发展

--allow-file-access-from-files 

然而,最优化的解决方案,在情况下,是安装Apache在本地通过http://localhost提供内容。这提升了file:///计划限制,因为所有浏览器都将使用http协议加载页面。

这些经常用于本地开发:EasyPHPWAMP,XAMPPBitNami

+0

。是的,EasyPHP是我目前的。 thx – Arfa

+0

@Arfa没有问题,我也使用EasyPHP。 '=]'不要忘记通过'http:// localhost'打开页面,因为'file:///'在没有允许文件访问标志的情况下会在Chrome中失败。 –