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.

Arfa
  • 105
  • 9
  • 1
    See if it helps http://stackoverflow.com/a/10866062/1331430 – Fabrício Matté Sep 23 '13 at 00:08
  • @FabrícioMatté - thanks for the links. You posted between my save and update. See above. Yes, I realise that I need to run my local version in a server environment, using Chrome. FF & IE are quite happy with the local relationship. I will try the "--allow-file-access-from-files" and see how that works. Thx. – Arfa Sep 23 '13 at 00:16

1 Answers1

0

Most likely you're opening the file using the file:/// scheme. Chrome won't allow direct access to the hard disk's files if doing so.

As my other answer mentions, there's an workaround for it running Chrome with this flag:

--allow-file-access-from-files

However, the most optimal solution, in case you plan to serious development using your local machine, is to install Apache locally to serve content through http://localhost. This lifts the file:/// scheme restrictions as all browsers will load the page using the http protocol.

These are often used for local development: EasyPHP, WAMP, XAMPP or BitNami.

Community
  • 1
  • 1
Fabrício Matté
  • 69,329
  • 26
  • 129
  • 166
  • @Arfa No prob, I also use EasyPHP. `=]` Just don't forget to open the page through `http://localhost` as `file:///` will fail in Chrome without the allow file access flag. – Fabrício Matté Sep 23 '13 at 00:19