Jquery loading does not work

Loading jquery in the code below does not work. What am I missing here?

<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"> </script> </head> <body style="font-size:62.5%;"> <div id="dialog" title="Dialog Title">I'm in a dialog</div> <script> $(document).ready(function() { $("#dialog").load('http://www.google.com/intl/en/about/index.html #maia-main'); }); </script> </body> </html> 
+4
source share
4 answers

You are requesting a page that is in a different domain, so cross-domain policies apply. You can only use cross-domain data transfer if the remote server allows it (and only using JSONP, I believe someone please correct me if I am wrong about this ). If you want to grab the source of the Google page, you need to do this from the server side script as a proxy for your jQuery:

 $(function() { //notice the client-side code (JS) is requesting a page on the save domain $("#dialog").load('my-script.php #maia-main'); }); 

And in my-script.php you will take the remote page you want:

 <?php //PHP, like all server-side languages has no cross-domain-policy echo file_get_contents('http://www.google.com/intl/en/about/index.html'); ?> 

Docs for file_get_contents() : http://www.php.net/file_get_contents

+5
source

try moving your script to server, jquery ajax does not always work on local.

+2
source

Script Execution

When calling .load() using a URL without a suffix for the selector expression, the content is passed .html() until the scripts are deleted. This is done before the script blocks before dropping them. However, if .load() is called with a selector expression appended to the URL, the scripts are deleted before the DOM is updated and thus are not executed. An example of both cases can be seen below:

Here, any JavaScript loaded in #a as part of the document will succeed.

 $('#a').load('article.html'); 

However, in the following case, the script blocks in the document loaded in #b are deleted and not executed:

 $('#b').load('article.html #target'); 

Source: jQuery.com

0
source

To load an external link in ".load ()"

create a page, say external.php

In the external.php file, enter the following code:

 <?php $url = 'http://ur/url/here'; echo $var = get_file_contents($url); ?> 

Now load this page in jquery n, it will load the external link

$ ('DIV') load ('external.php') ;.

0
source

Source: https://habr.com/ru/post/1395855/


All Articles