简体   繁体   中英

How to request div content from another site

I'm currently working on making an chrome app that uses javascript to make download buttons. I want the app to take the current page + append "/download" on it. Then it would request HTML code from that link.

<div class="download-row">
<a href="http://www.website.com">A website</a>
</div>

It would take the href from the download page, then create buttons with the href on the original page.


OK I tried this on the website and I'm having syntax issues.

var links = ""
$('#right').load('www.mywebsite.com/download', function(data) {
data.find(".download-row a").each(function(){
    links += $(this).attr("href");

    });});

When I tested this in chrome's console, it printed out:

GET http://www.mywebsite.com/download 404 (Not Found)
Uncaught TypeError: Object <!DOCTYPE html>
<html lang="en-us">
<head>
....
....
HTML data from the page.

You can use http://api.jquery.com/load/ to load data from other page. A sample example from jQuery documentation

$('#result').load('ajax/test.html #container');

There are many other demos available, try it. And if not use Ajax.

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