Usando l'ultimo jQuery (1.9.0), sono confuso sul motivo per cui questo codice non funziona:jQuery Ajax Get Errore di dati di sintassi, l'espressione non riconosciuta:
$.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();
Durante la visualizzazione della console, su clic su uno dei collegamenti di categoria, GET recupera l'intera pagina nella sua risposta, ma viene quindi seguita da un errore di sintassi, espressione non riconosciuta: (elenca tutto l'HTML dalla pagina recuperata). Quindi, qualcosa sta andando storto in $.fn.getFaqList
, probabilmente l'uso di $(data)
?
C'è qualcosa di ovvio che sto sbagliando? Qualsiasi aiuto sarebbe molto apprezzato. Non sono molto esperto con le cose AJAX.
Fare un .find ('a') – karthikr
Se siete su 1.8+ potete provare '$ ($. ParseHTML (dati)). Find' – Musa
Grazie Musa! L'ha fatto! Lo aggiungerò alla mia domanda – beefchimi