0

我的 html 中有以下代码。我无法提醒我寄回任何东西。

    $.ajax({
    url:"proxy.php?url=http%3A%2F%2Fapi.rottentomatoes.com%2Fapi%2Fpublic%2Fv1.0%2Flists%2Fmovies%2Fupcoming.json%3Fpage_limit%3D16%26page%3D1%26country%3Dus%26apikey%3Dk4uaze4937mw3hf82upstxqw%0A",
    type:'GET',
    dataType:"json",
    success:function(data){var title1 = data.movies[1].title; alert (title1);}
});

这是我的 proxy.php 文件。

<?php
    // File Name: proxy.php
    if (!isset($_GET['url'])) die();
    $url = urldecode($_GET['url']);
    $url = 'http://' . str_replace('http://', '', $url); // Avoid accessing the file system
    echo file_get_contents($url);

我正在使用代理,因为我尝试连接的服务器没有 jsonp。

这是我正在调用的 api,以及 json http://api.rottentomatoes.com/api/public/v1.0/lists/movies/upcoming.json?page_limit=16&page=1&country=us&apikey=k4uaze4937mw3hf82upstxqw

4

1 回答 1

0

现在工作。JSONP 没问题,你可以在没有 PHP 的情况下使用它。

<script type="text/javascript">

        $( document ).ready(function() {

            $.ajax({

                url:'http://api.rottentomatoes.com/api/public/v1.0/lists/movies/upcoming.json?page_limit=16&page=1&country=us&apikey=k4uaze4937mw3hf82upstxqw',
                type:'GET',
                dataType:'jsonp',

                success:function(data){

                    alert(data);

                    var title1 = data.movies[1].title; 
                    alert(title1);

                },

                error: function(xhr, textStatus, errorThrown){
                    alert(xhr);
                    alert(textStatus);
                    alert(errorThrown);
                }



            }); 



        });

    </script>
于 2013-08-31T18:27:35.397 回答