簡體   English   中英

jQuery Ajax頁面加載失敗

[英]jQuery Ajax Page Loading Fails

我想要單擊屬性為“ linkdata” =“ page”的鏈接以將正文的代碼更改為加載圖像,並在完成后將整個文檔的HTML更改為結果。 這是我當前的代碼:

$('a[linkdata="page"]').each(function() {
  $(this).click(function () {
    var attribute = $(this).attr("href");
    $("body").html('<center><img src="/ajax-loader.gif" /></center>');
    $.ajax({ type: "GET", url: attribute }).done(function (data) { 
      $(document).html(data); 
    });
    return false;
  });
});

結果:它將主體的HTML代碼更改為圖像,並且始終因請求而失敗(該請求為http://somelink.com/home-使用CodeIgniter,嘗試使用.fail(function() { window.location="/error/404" });

$('a[linkdata="page"]').click(function(e){
  e.preventDefault();
  $("body").html('<center><img src="/ajax-loader.gif" /></center>');
  $.ajax({url:$(this).attr("href") })
   .success(function(data){$(document.body).html(data);})
   .error(function(x,s,e){alert('Warning! '+s+': '+e)});
});
$('a[linkdata="page"]').on('click',function(k,v){
   var attribute = $(this).attr("href");
   $("body").html('<center><img src="/ajax-loader.gif" /></center>');
    $(document).load({ type: "GET", url: attribute });
  })

暫無
暫無

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

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