0

我想只使用 javascript 和 ajax 从网页获取数据。我的网页正在返回一个数组,我想在我的 html 页面上显示它。我不能用这个来使用php。

这是我正在使用的代码。

<html>
    <head>
        <title>Getting Started Extension's Popup</title>
        <script src="background.js">
        </script>
        <script type="text/javascript">
            $.ajax({
                url:"http://www.mydomain.com/page1.php?url='http://open.live.bbc.co.uk/weather/feeds/en/2643743/3dayforecast.rss'",
                type: 'GET',
                dataType: 'jsonp'
            });

            function callback(data){
                $('#iec_azn_data').html(data.results[0]);
            }
        </script>
    </head>
    <body>
        Hi
        <div id="iec_azn_data">

        </div>
    </body>
</html>
4

1 回答 1

1

success$.ajax选项中分配一个功能。当您的请求成功返回时,将调用该函数。

$.ajax({
  url:"http://www.mydomain.com/page1.php?url='http://open.live.bbc.co.uk/weather/feeds/en/2643743/3dayforecast.rss'",
  type: 'GET',
  dataType: 'jsonp',
  success : function(data){
    //data is a variable containing the returned data
  }
});
于 2013-04-15T11:36:45.237 回答