2013-08-31 15 views
0

我在我的HTML代碼如下。我無法保持警覺,無法將任何東西寄回給我。我不能得到這個Ajax調用工作,沒有JSON輸出

$.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

+0

顯示JSON數據 – Ventura

+0

嗨,我添加了api和json。 – tcui222

回答

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> 
+0

非常感謝,這正是我想要做的 – tcui222

相關問題