0

I am trying to load another Url into div tag using jquery on click function. But it loads the same page into the div tag.

Below is my code:

Jquery:

function loadPage() {
    $('#xterm').load('http://google.com',function () {
        alert('Page Loaded');
    });
}

HTML:

button:

<button class="btn btn-primary Border" type="button" onclick="loadPage()">

div:

<div class="ScrollStyles1" id="xterm"> </div>
2
  • I don't think you can load an external URL using .load(). Look here for info on how to load external URL's: stackoverflow.com/questions/8849668/… Commented Mar 1, 2017 at 6:03
  • I tried it doesn't load external URL. Thanks for your help @Joshua Terrill Commented Mar 1, 2017 at 6:33

1 Answer 1

3

Your code is working well but browser ignores it due to security reason. Please run your code and check console here is the console error

for this you need to do is The URL to be loaded must either be on the same domain as the page that's calling it, or enable cross-origin HTTP requests.

You should download extension for Access-Control-Allow-Origin:* in browser to see the effects.

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

3 Comments

Both are same domain. I test both in local server only i.e: locahost. How to enable cross-origin requests
Check you console by inspect element and check error. I hope so your are getting some error.
Wow what a prediction. Yeah! you're right am getting some error in console. Thanks!!!!!

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.