0

I'm messing around with the wonderful world of jQuery (since I eventually want to make good web apps/games) and I got to the .load and .get topics. I saw (here and some other places) that you can insert a page's html into a div if so desired. I attempted this on jsFiddle but the results were what they are supposed to be. What am I doing wrong?

<button id="btn1" type="button">Click!</button>
<div id="box1" style="width: 100px; height:100px"></div>
<div id="box2" style="width: 100px; height:100px"></div>

and

$('#btn1').click(function () {
    $('#box1').load('http://stackoverflow.com');
    $('#box2').load('http://stackoverflow.com');
});

I tried the same code in a bunch of different browsers but still no luck. What am I doing wrong?

3
  • 3
    you can't .load something from a different origin unless both the client and the cross-origin server supports CORS. Try using a local file instead. Commented Mar 28, 2013 at 21:18
  • You can load them in an IFrame though Commented Mar 28, 2013 at 21:20
  • yeah I already do that, but I wanted to see if this was possible. Commented Mar 28, 2013 at 21:21

1 Answer 1

2

You can't do this due to the Same Origin Policy

You can't load data from domains outside of the calling script

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.