失踪 ;在API RESULT jquery中的before语句

时间:2016-02-09 10:45:43

标签: jquery ajax api

我使用JQUERY调用API,并且得到此错误我不知道我做错了什么。这是我的代码

<html>
<head>
    <title>My Movie App</title>
    <script src="Jquery.min.js"></script>
    <script>

        $(document).ready(function(){
            var Title, Desc, Rating, Rel_Date;
            $.ajax({
                type:"GET",
                url:"https://api.cinemalytics.com/v1/movie/id/e80b298d/?auth_token=***********************************",
                dataType:"jsonp",
                //datatype : "application/jsonp",
                contentType: "application/json",
                success: function(json){
                    //alert(json);
                    //$("#div1").append(json.id);
                    console.log(JSON.stringify(json));
                }
            });
        });


    </script>
</head>
<body>
    <table>
        <tr>
            <td>Title</td>
            <td>Description</td>
            <td>Rating</td>
            <td>Release Date</td>
        </tr>
    </table>
    <div id="div1"></div>
</body>

image

这是我想要的结果。

{"Id":"e80b298d","ImdbId":"tt0248126","OriginalTitle":"Kabhi Khushi Kabhie Gham","Title":"Kabhi Khushi Kabhie Gham","Description":"Yash Raichand is a wealthy business man married to Naina Raichand and has two sons, Rahul and Rohan. Rahul was adopted since he was born. Rahul falls in love with a poor girl named Anjali but his dad forbids their love, for he has wanted him to marry his friend's daughter. Rahul marries Anjali, so his dad kicks him out of the house and moves to London with Anjali, Pooja (her young sister), and his nanny. Ten years later, Rahul and Anjali have a sum named Krish who is in forth grade. Rohan then graduates from boarding school and insists on reuniting the family together. Will he reunite them again?","TrailerLink":"","TrailerEmbedCode":"","Country":"IN","Region":"BOLLYWOOD","Genre":"Family","RatingCount":19,"Rating":4.1,"CensorRating":"U/A","ReleaseDate":"12/14/2001","Runtime":210,"Budget":400000000,"Revenue":1350000000,"PosterPath":"https://s3-ap-southeast-1.amazonaws.com/cinemalytics/movie/DF7D2E5CB4EA9B4F1497A159383BADF5.jpg"}

修改

如果我按照其他答案中的建议将数据类型更改为Json我遇到以下错误: 跨源请求已阻止:同源策略禁止读取远程资源。 (原因:缺少CORS标题'Access-Control-Allow-Origin'。

1 个答案:

答案 0 :(得分:0)

我认为您的问题是API不支持JSONP。设置中间服务器来处理API请求,然后通过AJAX调用您的服务器。

关于此,有很多类似的问题; such as this one.