简体   繁体   English

图片的jQuery JSONP请求获取403错误

[英]jQuery JSONP request of image gets 403 error

OK I have a simple script at http://kleague.org/test/ 好的,我在http://kleague.org/test/有一个简单的脚本

Type a movie name and it should output the movie name, year, and get the movie poster URL (if there is one, there usually is.) 输入电影名称,它应该输出电影名称,年份并获得电影海报的URL(如果有,通常是。)

Well, I just tried it and I got a 403 error on the image. 好吧,我刚刚尝试过,但是图像上出现403错误。 it GOT the image but it didn't display it. 它获得了图像,但没有显示。 What am I doing wrong? 我究竟做错了什么?

<!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 requires a function/script to be returned. JSONP需要返回一个函数/脚本。 Loading an image through AJAX has no use. 通过AJAX加载图像没有用。 Just appending the image itself will do the trick. 只需附加图像本身即可解决问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM