0

I am trying to grab a webpage using the $.get() jQuery function, and so far have been unsuccessful.

I have the following function:

$.get("http://www.lavancier.com/brockCharts/actual-data.html", function(response) { 
document.write(response);
});

That has a valid URL and inside that url is a json (just on a plain html page however). When I try to write the contents, nothing happens. Anyone know why?

Thanks!

http://jsfiddle.net/brockwhittaker/pxq2kkkf/

2 Answers2

0

It is a server config. The server is denying ajax request outside its origin.

It will work if the server has header Access-Control-Allow-Origin: * set. Or, if you move your script to the same origin.

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
0

If you look in the console (I am using chrome) I can see that you are getting the following error:

XMLHttpRequest cannot load http://www.lavancier.com/brockCharts/actual-data.html. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.

You need to add a header to lavancier.com which allows cross domain. See Origin is not allowed by Access-Control-Allow-Origin

Community
  • 1
  • 1
tomf
  • 449
  • 4
  • 13