Alex Adams
Alex Adams

Reputation: 67

Best way of making an Ajax call from Jquery

I am trying to just load a page using AJAX like this, I am very new to Jquery and ajax,please let me know what mistake I am doing here, always i get the error page.

<html>
<head>
   <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="ajax-panel">

</div>
<script>
$.ajax({
  url: 'http://www.cnn.com',
   success:function(data){
   alert(data);
  },
  error:function(){
    // failed request; give feedback to user
    $('#ajax-panel').html('</p> Try that again in a few moments.</p>');
  }
});
 </script>

</body>
</html>

Upvotes: 1

Views: 146

Answers (1)

user1026361
user1026361

Reputation: 3657

You can't make *AJAX requests to a page on another domain. You'll want to read about CORS and look into your options. The easest way is to poll a back end resource on your server that aggregates the data for you

Upvotes: 3

Related Questions