简体   繁体   English

jQuery Ajax页面加载失败

[英]jQuery Ajax Page Loading Fails

I want when I click a link with attribute "linkdata" = "page" to change the body's code to a loading image and after it's done to change the whole document's HTML to the result. 我想要单击属性为“ linkdata” =“ page”的链接以将正文的代码更改为加载图像,并在完成后将整个文档的HTML更改为结果。 Here is the current code I have: 这是我当前的代码:

$('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;
  });
});

The result: It changes the body's HTML code to the image and always fails with the request (which is http://somelink.com/home - using CodeIgniter, tried with .fail(function() { window.location="/error/404" }); ) 结果:它将主体的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