Search code examples
ajaxjqueryjquery-load

Load text from specific external DIV using AJAX?


I'm trying to load up the estimated world population from http://www.census.gov/ipc/www/popclockworld.html using AJAX, and so far, failing miserably.

There's a DIV with the ID "worldnumber" on that page which contains the estimated population, so that's the only text I want to grab from the page.

Here's what I've tried:

  $(document).ready(function(){
    $("#population").load('http://www.census.gov/ipc/www/popclockworld.html #worldnumber *');
  });

Solution

  • What you are trying to do is known as a cross-domain request. This is not a feature that browsers normally allow (security feature). Some ways to get around this limitation are described here: The jQuery Cross-Domain Ajax Guide.