2

I'm trying to extract some information from a external website with Jquery .load() method, But this doesn't seem to be working, any thoughts why? I tested on both firefox and chrome.

 <!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#div1").load("http://www.weather.com/weather/5-day/CEXX0001 #wx-forecast-container");
  });
});
</script>
</head>
<body>

<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>

</body>
</html>
ycr
  • 12,828
  • 2
  • 25
  • 45

2 Answers2

10

It will throw an error
No 'Access-Control-Allow-Origin' header is present on the requested resource

Reason is you can not access external domain url through XmlHttpRequest.

Alternative is create server side intermediater that pull data from weather.com and serve to your page using load or ajax method.

Rashmin Javiya
  • 5,173
  • 3
  • 27
  • 49
1

You are facing crossdomain policy restrictions. Browser simply won't allow you to load content from external website, You can try to place crossdomain.xml on weather.com, however you can't

Vlad Miller
  • 2,255
  • 1
  • 20
  • 38