How embarrassing. I had this working on a previous project, but now i am unable to get the simplest examples
of load and $.get to work right.
My simple little web page is shown below. When i use firebug i can see that http requests are being made
(in the case below to cnn.com, i also tried google.) But firebug shows these requests in red for some reason.
The div with id ‘container’ does not get updated. and i never see the callback indicating ‘here is the data’.
Must be something real simple and dumb..but after tinkering for an hour i’m ready to cry for help.
any advice much appreciated. Thanks !
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
alert('in ready handler');
$('#container').load('http://www.cnn.com/');
alert('after container load');
$.get(
'http://www.cnn.com/',
function(data) {
alert('here is the data' + data);
}
);
alert('after get was called');
});
</script>
</head>
<body>
the container:
<div id="container"></div>
</body>
</html>
This is a cross domain protection mechanism.
The best option is to have a simple php file on your server which requests the content from the remote site and send it back e.g.
AJAX.php
You JS