2

I am trying to load external website #external-div content to the page on #mydiv div. I have tried by attaching this jquery

<script src="js/jquery-1.8.2.min.js"></script>

and script is

<script>
    $(document).ready(function(){
        $('#mydiv').load('http://localhost/qa/ask #external-div');
    });
</script>

My div

<div id="mydiv">loading...</div>

I have downloaded jquery from here http://jquery.com/download/?rdfrom=http%3A%2F%2Fdocs.jquery.com%2Fmw%2Findex.php%3Ftitle%3DDownloading_jQuery%26redirect%3Dno

But its not loading anything.

Code Lover
  • 8,099
  • 20
  • 84
  • 154
  • Do you have some errors? – Alessandro Minoccheri Oct 17 '12 at 15:57
  • The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol. – Code Lover Oct 17 '12 at 15:59
  • I have added character set and now no error but still not loading content. Am I embedding right jquery? – Code Lover Oct 17 '12 at 16:02
  • Your script link is fine, assuming it's in the right place. What's the space doing in the url in the load line? – Reinstate Monica Cellio Oct 17 '12 at 16:02
  • show the http://localhost/qa/ask file – zetsin Oct 17 '12 at 16:03
  • okay i have tried with removing space but still not loading `$('#mydiv').load('http://localhost/qa/ask#external-div');`` – Code Lover Oct 17 '12 at 16:04
  • Now I checked and getting error like this `GET http://localhost/qa/ask 200 OK 106ms` – Code Lover Oct 17 '12 at 16:05
  • It is a form to submit question. Long file where I can place? – Code Lover Oct 17 '12 at 16:08
  • `$('#mydiv').load('localhost/qa/ask');`——can get anything? – zetsin Oct 17 '12 at 16:11
  • I tried this and still not getting anything. Even I have tried with live/production website but still not loading anything. – Code Lover Oct 17 '12 at 16:12
  • try $('#mydiv').load('http://localhost/qa/ask');——i miss http above and $('#mydiv').load('/qa/ask');——relative path – zetsin Oct 17 '12 at 16:19
  • But my site is not on relative path. I am trying to create one script where my user can embed this div into them web page to load my question form and them user can submit question to my site from that div instead of come to my website – Code Lover Oct 17 '12 at 16:21
  • 1
    i think jquery.load() function is not surpported accessing cross-domain – zetsin Oct 17 '12 at 16:37
  • Ah than how can I load it? can I fix frame with iframe and if I want to move page to little top in iframe is it possible? – Code Lover Oct 17 '12 at 16:40
  • Yes you are right it is not supporting cross domain. :( – Code Lover Oct 17 '12 at 16:48
  • Possible duplicate of [Ajax/jQuery - Load webpage content into a div on page load?](http://stackoverflow.com/questions/9963799/ajax-jquery-load-webpage-content-into-a-div-on-page-load) – Matt Nov 03 '15 at 13:50

1 Answers1

3

try code bellow to get callback respon:

$('#mydiv').load('http://localhost/qa/ask #external-div', function(response, status, xhr) {
    if (status == "error") {
        var msg = "Sorry but there was an error: ";
        alert(msg + xhr.status + " " + xhr.statusText);
      }
});
Habibillah
  • 27,347
  • 5
  • 36
  • 56