다음 코드는 페이지를 요청할 때 this과 같은 오류를 표시하며 404 오류가 발생합니다. 대신 경고가 나타납니다. 이상한 점은 은에 ajaxed 된 링크에서만이 작업을 수행한다는 것입니다. 업데이트/변경하지 않는 링크에서는 정상적으로 작동합니다. 그것은 당신의 성공 핸들러 코드에 뭔가가 어떤 종류의 오류의 원인이되는 경우는 아마도
('.page-wrap').append('<img src="img/graphics/ajax-loader.gif" class="ajax-loader" />');
var target = $('section.content'),
siteURL = 'http://' + top.location.host.toString(),
internalLinks = $("a[href^='"+siteURL+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']"),
links = $('a'),
URL,
el,
mainContent,
headContent,
headClasses,
pageName,
ajaxSpinner = $('.ajax-loader');
internalLinks.click(function(e) {
el = $(this);
URL = el.attr('href');
$('.current_page_item').removeClass('current_page_item');
el.addClass("current_link").parent().addClass("current_page_item");
ajaxLoader(URL, false);
e.preventDefault();
});
function ajaxLoader(location, isHistory) {
$("html, body").animate({ scrollTop: "0px" });
ajaxSpinner.show();
$('.page-wrap').css('opacity', '0.5}');
// Load New Page
$.get(location, function(data) {
mainContent = $('section.content', data).html();
headContent = $('.feature-content', data).html();
pageName = $('.page-name', data).html();
headClasses = $('header', data).attr('class');
$('section.content').html(mainContent);
$('.page-name').html(pageName);
$('.feature-content').html(headContent);
if (headClasses) {
$('header').attr('class', headClasses);
} else {
$('header').removeClass();
}
if (!isHistory) {
history.pushState(location, '', location);
}
$(resizeHeader);
ajaxSpinner.fadeOut();
}).error(function() {
alert('woops'); // or whatever
});
}
w.bind('popstate', function(event) {
if (event.originalEvent.state !== null) {
ajaxLoader(event.originalEvent.state, true);
}
});
정확히 무엇을 원하니? – Brian
AJAX로 페이지를로드하려고하는데 오류가있는 경우 (예 : 404) 사용자에게 알립니다. 위의 코드는 작동하지만 '.error'부분을 추가하면 에러가 발생합니다. – George
@George,이 줄의 목적은 무엇입니까 :'mainContent = $ ('section.content', data) .html();'etc? 나는 그들이 왜 필요한지 알 수 없다 .... –