最新の jQuery (1.9.0) を使用して、このコードが機能しない理由について混乱しています。
$.testAjaxFilter = function() {
var base = this;
// get faq categories
var currentFaqCategories = $('#category-list ul li a');
// loop through each faq category link and bind a click event to each
if ( typeof currentFaqCategories !== 'undefined') {
$.each(currentFaqCategories, function(index, category) {
$(category).click( function(e) {
$(e.target).getFaqList();
return false;
});
});
}
// GET faq list elements from category link
$.fn.getFaqList = function() {
$.get($(this[0]).attr('href'), function(data) {
base.addFaqSectionToPage( $(data).find('section.faq-page #content-column') );
});
};
// add new faq section to current page
this.addFaqSectionToPage = function(faqSection) {
// remove old faq section
var currentFaqSection = $('section.faq-page #content-column');
currentFaqSection.empty();
currentFaqSection.append(faqSection);
};
};
$.testAjaxFilter();
コンソールを表示しているときに、カテゴリ リンクの 1 つをクリックすると、GET はその応答でページ全体を取得しますが、その後に構文エラー、認識されない式: (取得したページからすべての HTML をリストします) が続きます。で何か問題が発生しています。$.fn.getFaqList
おそらく$(data)
?の使用です。
私が間違っていることは明らかですか?どんな助けでも大歓迎です。私は AJAX に精通していません。