Question

I have the code below in my html. I can't get alert to send me back anything.

    $.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);}
});

here is my proxy.php file.

<?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);

I am using proxy because the server I am trying to connect to does not have jsonp.

This is the api I am calling, and the json http://api.rottentomatoes.com/api/public/v1.0/lists/movies/upcoming.json?page_limit=16&page=1&country=us&apikey=k4uaze4937mw3hf82upstxqw

Was it helpful?

Solution

Now works. JSONP is ok, you can use it without your 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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top