1

嗨,我是使用 API 的新手,在尝试从 cineworld api 检索信息时遇到问题,有没有人使用过它。

这是他们给出的一个例子,但我似乎无法从中提取任何信息?

<script>
$(document).ready(function() {
$('a.retrieve').click(function() {
    $.ajax({
        url: '/api/quickbook/films',
        type: 'GET',
        data: {key: 'qUnEyRXt', full: true, cinema: 33},
        dataType: 'jsonp', // Setting this data type will add the callback parameter for you
        success: parseFilms
    });
});

$('a.clear').click(function() {
    $('span.film.count').text('0');
    $('ol.film.list').empty();
});
});

 function parseFilms(response, status) {
var html = '';

// Check for errors from the server
if (response.errors) {
    $.each(response.errors, function() {
        html += '<li>' + this + '</li>';
    });
} else {
    $('span.film.count').text(response.films.length);
    $.each(response.films, function() {
        html += '<li>' + this.title + ' (' + this.classification + ')</li>';
    });
}

// Faster than doing a DOM call to append each node
$('ol.film.list').append(html);
}


</script>  

网络文档的链接是https://www.cineworld.co.uk/developer/jquery

任何帮助或建议都会非常感谢

4

1 回答 1

0

实际上,它有效!

这是您要传递的网址$.ajax()

http://www.cineworld.co.uk/api/quickbook/films?key=qUnEyRXt&full=true&cinema=33

这是代码

<html>
  <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
        $('a.retrieve').click(function() {
          $.ajax({
              url: 'http://www.cineworld.co.uk/api/quickbook/films',
              type: 'GET',
              data: {key: 'qUnEyRXt', full: true, cinema: 33},
              dataType: 'jsonp', // Setting this data type will add the callback parameter for you
              success: parseFilms
          });
        });

        $('a.clear').click(function() {
            $('span.film.count').text('0');
            $('ol.film.list').empty();
        });
      });

      function parseFilms(response, status) {
        var html = '';

        // Check for errors from the server
        if (response.errors) {
            $.each(response.errors, function() {
                html += '<li>Error' + this + '</li>';
            });
        } else {
            $('span.film.count').text(response.films.length);
            $.each(response.films, function() {
                html += '<li>' + this.title + ' (' + this.classification + ')</li>';
            });
        }

        // Faster than doing a DOM call to append each node
        $('ol.film.list').html(html);
      }
    </script>  
  </head>
  <body>
    <a class="retrieve" href="#retrieve">Retrieve</a>
    <a class="clear" href="#clear">Clear</a>
    <span class="film count"></span>
    <ol class="film list">
    </ol>
  </body>
</html>
于 2013-01-10T00:30:47.613 回答