简体   繁体   中英

load div from another page with jquery

i would like to load a div from a page in my page with jquery

Here is a Jsfiddle but it doesn't work, what is wrong in my code ?

In my example I'm using

$('.namebook1origin').load($('http://www.booclin.ovh/tom/last/update.html #namebook1'));

but in my page I'm using

$('.namebook1origin').load($('update.html #namebook1'));



Here is a live example

 $('.namebook1origin').load($('http://www.booclin.ovh/tom/last/update.html #namebook1')); $('.namebook2origin').load($('http://www.booclin.ovh/tom/last/update.html #namebook2')); $('.namebook3origin').load($('http://www.booclin.ovh/tom/last/update.html #namebook3')); $('.namebook4origin').load($('http://www.booclin.ovh/tom/last/update.html #namebook4')); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span class="namebook1origin">.</span><br/> <span class="namebook2origin">.</span><br/> <span class="namebook3origin">.</span><br/> <span class="namebook4origin">.</span><br/> 

load accepts a string as input not a jquery object, unram the $() from the string

 $('.namebook1origin').load('http://www.booclin.ovh/tom/last/update.html #namebook1'); $('.namebook2origin').load('http://www.booclin.ovh/tom/last/update.html #namebook2'); $('.namebook3origin').load('http://www.booclin.ovh/tom/last/update.html #namebook3'); $('.namebook4origin').load('http://www.booclin.ovh/tom/last/update.html #namebook4'); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span class="namebook1origin">.</span><br/> <span class="namebook2origin">.</span><br/> <span class="namebook3origin">.</span><br/> <span class="namebook4origin">.</span><br/> 

The snippet doesn't work because of CORS

jQuery的.load()应该是这样的: $(selector).load("internalDomainURL #div",callback);

$("#namebook1origin").load("http://www.booclin.ovh/tom/last/update.html #namebook1");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM