I’ve only recently started using jQuery and am having no problems with most of it. I’ve just started to look at using Ajax calls and have immediately hit a stumbling block. To illustrate my problem I have written a small piece of demo code…
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$.get("http://www.google.co.uk", function(data) {
alert(data);
}, "html");
});
</script>
<style>
#page
{
border:1px solid black;
width:640px;
height:480px;
}
</style>
</head>
<body>
<div id="page"></div>
</body>
</html>
As you can see, the page loads and then it’s supposed to load the contents of a URL (google in this case) into the only div on the page, but it doesn’t work.
Using the developer tools in Chrome I can see the request being sent, but it’s marked as “canceled” (yes, with 1 l!)
I’d really appreciate someone helping me with what must be a really simple issue. As I said, this is literally my 1st attempt at doing this. It normally takes me a lot longer to get stuck!
Thanks in advance for any suggestions 🙂
I’d guess it’s a security issue. You can’t load pages from another server into your document. See http://api.jquery.com/load/ for more info.