简体   繁体   English

请求后请求 ajax 和 jquery 使用 $.ajax

[英]Request after request ajax and jquery using $.ajax

I am very new to Jquery and ajax so please be kind.我对 Jquery 和 ajax 很陌生,所以请善待。 i am making a request to the server using jquery $.ajax, the ajax pulls the image from the image id stored on the server/database when the user clicks on a thumbnail of which there are loads.我正在使用 jquery $.ajax 向服务器发出请求,ajax 从存储在服务器/数据库上的图像 id 加载缩略图时加载图像All works fine except with the following code i can only click on any of the thumbnails once to load the big picture from the database, after that no other thumbnail works.一切正常,除了使用以下代码我只能单击任何缩略图一次以从数据库中加载大图片,之后没有其他缩略图工作。 Can anyone help?任何人都可以帮忙吗?

<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
<script type="text/javascript">

function getimage(data){
var img = new Image();
$(img).load(function(){
    $(img).hide();
    $.ajax({
        type: "GET",
        url: "name.php?",
        data: "name=" + data,
        success: function(){
            $("#loader").removeClass("loading").append(img);
            $(img).fadeIn("slow");
        }
    });
}).attr("src", data +".jpg");
}
</script>
</head>
<body>
<h1>Image Loading</h1>
<div id="loader" class="loading">

</div>
<a href="name.php?name=image1" id="image1" onclick="getimage('image1'); return false;"/><img src="image1_th.jpg" /></a>
<a href="name.php?name=image2" id="image2" onclick="getimage('image2'); return false;" /><img src="image2_th.jpg" /></a>
<a href="name.php?name=image3" id="image3" onclick="getimage('image3'); return false;"/><img src="image3_th.jpg" /></a>    

try this:尝试这个:

function getimage(data){
var img = new Image();
$(img).load(function(){
    $(img).hide();
    $.ajax({
        type: "GET",
        url: "name.php?",
        data: "name=" + data,
        success: function(){
             $("#loader").html(''); // you need to remove the old image
            $("#loader").removeClass("loading").append(img);
            $(img).fadeIn("slow");
        }
    });
}).attr("src", data +".jpg");

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

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