1

Update
I just tested the link to my example and... damn thing works.! I am not convinced??? Any comments still welcome.

I have just updated my browsers and Chrome rejects my (previously working) ajax call to a simple text file containing html. Here is my current bare-bones code:

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

The Chrome console gives me:

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.

And the pointer in jquery - around line 8472 in ver 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 );

I have a stripped down version of my project here:
Null return on Ajax

I figure the ajax line is the problem and needs revision. I have tried a lot of alternate permutations but there so many options and my experience here is limited.

4

1 に答える 1

0

ほとんどの場合、file:///スキームを使用してファイルを開いています。その場合、Chrome はハードディスクのファイルへの直接アクセスを許可しません。

の他の回答が言及しているように、このフラグを使用して Chrome を実行するための回避策があります。

--allow-file-access-from-files

ただし、ローカル マシンを使用して本格的な開発を計画している場合の最適な解決策は、ローカルに Apache をインストールして、 を介してコンテンツを提供することhttp://localhostです。これにより、すべてのブラウザがプロトコルfile:///を使用してページをロードするため、スキームの制限が解除されます。http

EasyPHPWAMPXAMPP、またはBitNamiはローカル開発によく使用されます。

于 2013-09-23T00:11:31.213 に答える