簡體   English   中英

圖片的jQuery JSONP請求獲取403錯誤

[英]jQuery JSONP request of image gets 403 error

好的,我在http://kleague.org/test/有一個簡單的腳本

輸入電影名稱,它應該輸出電影名稱,年份並獲得電影海報的URL(如果有,通常是。)

好吧,我剛剛嘗試過,但是圖像上出現403錯誤。 它獲得了圖像,但沒有顯示。 我究竟做錯了什么?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />


    <title>IMDB api</title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>


    <script type="text/javascript">
    $(document).ready(function()
{




$('#search').click(function(){

$(".loading").css("display", "inline");


       var yourMovie = $("#movie").val();
  $("#debug").append("You are searching for ... "+yourMovie+"\n");

dataString = "callback=?&t=" +yourMovie;

$.getJSON('http://www.imdbapi.com/', dataString, function(html){

$(".loading").css("display", "none");

    var movieSugg = html.Title;
    var movieYear = html.Year;
    var movieImg = html.Poster;

$("#movieposter").attr("src", movieImg);
$("#movieposter").css("display", "inline");

$("#more").append("You found: " + movieSugg + " ("+movieYear+") ["+movieImg+"] \n");
});

});


});
</script>

</head>
<body>

<img src="" alt="Poster" id="movieposter" style="display: none;float:left;margin-right:10px;" />
<form method="get" action="#" enctype="text/html" > 
<input type="text" id="movie" maxlength="50" /> <a href="#" id="search">Search now!</a> <img alt="Searching..." style="display: none;" class="loading" src="ajax-loader.gif" title="Searching..." />

</form>

<div id="other">

  Trigger the handler
</div>
<br />
<textarea id="debug" style="width: 500px;height:150px;border:1px solid black;font-face:typewriter;"></textarea><br />
<textarea id="more" style="width: 500px;height:150px;border:1px solid red;font-face:typewriter;"></textarea>

</body>
</html>

JSONP需要返回一個函數/腳本。 通過AJAX加載圖像沒有用。 只需附加圖像本身即可解決問題。

<img src="{html.poster here}" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM