4

Possible Duplicate:
XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin

I still don't get why this code works fine when loading local server pages (localhost) but display nothing when trying to fetch remote data

$(document).ready(function(){

    $.get(
    "message.html",
    function(data) { $("div").html(data); },
    "html"
    );
});

and displaying the remote html file gives me no error but no data:

$(document).ready(function(){

    $.get(
    "http://viralpatel.net/blogs/2009/04/jquery-ajax-tutorial-example-ajax-jquery-development.html",
    function(data) { $("div").html(data); },
    "html"
    );
});

Regards

Community
  • 1
  • 1
Kandinski
  • 953
  • 11
  • 30
  • maybe duplication here: `http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin` – yuli chika Oct 06 '11 at 11:51
  • doesn't seem like it. His problem is that he's trying to do cross-domain requests with ajax, which isn't allowed. He'll have to make a serverside page on the same domain that makes the call out and then returns the result. – Atheist Oct 06 '11 at 11:55

1 Answers1

4

There is a built-in restriction to prevent cross-domain Ajax requests from the browser. Pretty much all browsers implement this.

There are workarounds such as the article here or using JSONP. But this is a basic restriction put on Ajax requests sent from the browser. If you are using ASP.NET Encosia also had a good tip on doing the proxying using a custom HttpHandler.

See also: Cross Domain Limitations With Ajax - JSON

Community
  • 1
  • 1
njr101
  • 9,499
  • 7
  • 39
  • 56
  • `$(document).ready(function(){ $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?", function(data){ $.each(data.items, function(i,item){ $("").attr("src", item.media.m).appendTo("#images"); if ( i == 3 ) return false; }); }); });` – Kandinski Oct 06 '11 at 12:20