Ajax调用在成功后不起作用

时间:2015-12-16 19:02:29

标签: javascript jquery ajax

成功后我遇到了ajax调用问题。

我正在尝试拨打以下javascript代码:

function imgResize($, sr) {

  var debounce = function(func, threshold, execAsap) {
      var timeout;

      return function debounced() {
        var obj = this,
          args = arguments;

        function delayed() {
          if (!execAsap)
            func.apply(obj, args);
          timeout = null;
        };

        if (timeout)
          clearTimeout(timeout);
        else if (execAsap)
          func.apply(obj, args);

        timeout = setTimeout(delayed, threshold || 100);
      };
    }
    // smartresize 
  jQuery.fn[sr] = function(fn) {
    return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr);
  };

};

//CALL ON PAGE LOAD OR ANY TIME YOU WANT TO USE IT
imgResize(jQuery, 'smartresize');

/* Wait for DOM to be ready */


  // Detect resize event
  $(window).smartresize(function() {
    // Set photo image size
    $('.photo-row').each(function() {
      var $pi = $(this).find('.photo-item'),
        cWidth = $(this).parent('.photo').width();

      // Generate array containing all image aspect ratios
      var ratios = $pi.map(function() {
        return $(this).find('img').data('org-width') / $(this).find('img').data('org-height');
      }).get();

      // Get sum of widths
      var sumRatios = 0,
        sumMargins = 0,
        minRatio = Math.min.apply(Math, ratios);
      for (var i = 0; i < $pi.length; i++) {
        sumRatios += ratios[i] / minRatio;
      };

      $pi.each(function() {
        sumMargins += parseInt($(this).css('margin-left')) + parseInt($(this).css('margin-right'));
      });

      // Calculate dimensions
      $pi.each(function(i) {
        var minWidth = (cWidth - sumMargins) / sumRatios;
        $(this).find('img')
          .height(Math.floor(minWidth / minRatio))
          .width(Math.floor(minWidth / minRatio) * ratios[i]);
      });
    });
  });


/* Wait for images to be loaded */
$(window).load(function() {

  $(".photo").each(function() {

    var imgGrab = $(this).find('.photo-item');
    var imgLength = imgGrab.length;

    for (i = 0; i < imgLength; i = i + 3) {
      imgGrab.eq(i + 1)
        .add(imgGrab.eq(i + 1))
        .add(imgGrab.eq(i + 2))
        .wrapAll('<div class="photo-row"></div>');
    }

    $(this).find(".photo-item").each(function() {
      if ($(this).parent().is(":not(.photo-row)")) {

        $(this).wrap('<div class="photo-row"></div>');
      }
    });

    // Store original image dimensions
    $(this).find('.photo-item img').each(function() {
      $(this)
        .data('org-width', $(this)[0].naturalWidth)
        .data('org-height', $(this)[0].naturalHeight);
    });

  });

  $(window).resize();
});

这是我的LOAD MORE POST

的ajax代码
$('body').on("click",'.morep', function(event) {
    event.preventDefault();
    var ID = $(this).attr("id");
    var P_ID = $(this).attr("rel");
    var URL = $.base_url + 'more_post.php';
    var dataString = "lastpid=" + ID + "&post_id=" + P_ID;

    if (ID) {
      $.ajax({
        type: "POST",
        url: URL,
        data: dataString,
        cache: false,
        beforeSend: function() {
          $("#more" + ID).html('<img src="loaders/ajaxloader.gif" />');
        },
        success: function(html) {
          $("div.post-content").append(html);
          $("#more" + ID).remove();
          imgResize(jQuery, 'smartresize');
        }
      });
    } else {
      $("#more").html('FINISHED');
    }
    return false;
  });

ajax应该调用imgResize(jQuery, 'smartresize');但它不起作用。我在这里想念的是谁能在这里帮助我?

0 个答案:

没有答案