用js从其他页面获取数据

Get data from other page with js?

本文关键字:获取 数据 其他 js      更新时间:2023-09-26

我想从其他页面获得数据与js或jquery或ajax,但不是php。我刚找到一个堆栈溢出的例子。但是当我在我的index.html文件上编写这些代码时,它不起作用。我不懂道理。这是我的代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
    <script type=”text/javascript”>
       var url='http://query.yahooapis.com/v1/public/yql?q=select * from html where url=''https://stackoverflow.com/'' and xpath=''//div[@id="question-mini-list"]//h3//a''&format=json&callback=?';

        $.getJSON( url, function(data){
            $.each(data.query.results.a, function(){       
                $('body').append('<div><a href="http://stackoverflow.com'+this.href +'">'+this.content+'</a></div>');    
             });
        });
    </script>
</head>
<body>  
    <div></div>
</body>
</html>

它的工作原理是…

var url='http://query.yahooapis.com/v1/public/yql?q=select * from html where url=''http://stackoverflow.com/'' and xpath=''//div[@id="question-mini-list"]//h3//a''&format=json&callback=?';
$.getJSON( url, function(data){
    $.each(data.query.results.a, function(){       
        $('body').append('<div><a href="http://stackoverflow.com'+this.href +'">'+this.content+'</a></div>');    
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div></div>

这些代码我解决了我的问题,谢谢你的帮助

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function(){
            var url = 'deneme.html';
            $.get(url, function(response) {
                $('div#external').html($(response).find('#content>ul>li').html());
            });
        });
      </script>
    <style> body, html{padding: 0; margin:0;}</style>
</head>
<body>  
    <div id="external" >
    </div>
</body>
</html>