jQuery图像替换

时间:2011-07-17 03:51:35

标签: jquery

我正在尝试用图库中的图像替换一些主要图像。一切都在工作,而不是替换html img似乎没有加载。由于某种原因,数据未加载。有任何想法吗?以下是我到目前为止的情况:

$(function() {
 $(".thumbs li a").each(function() {
 var $thumb = $(this);
 $thumb.click(function(event) {
  event.preventDefault();

  var image_container = $thumb.parent().parent().parent().find('.image');
  var loading = $thumb.parent().parent().parent().find('.loading');

  $.ajax({
    beforeSend: function() {
      image_container.css('display', 'none');
      loading.css('display', 'inline-block');
    },
    url: 'image.php',
    data: ({src : $(this).attr('href')}),
    dataType: 'html',
    complete: function(data) {
      loading.css('display', 'none');
      image_container.css('display', 'inline-block');
      image_container.html(data);
      $thumb.parent().siblings().removeClass('active');
      $thumb.parent().addClass('active');
    }
   });
  });
 });
});

1 个答案:

答案 0 :(得分:3)

使用success event instead of complete。因为complete()的第一个参数是jqXHR对象,而不是响应。

相关问题