采用最新的jQuery(1.9.0),我很困惑,为什么这code不工作:
Using the latest jQuery (1.9.0), I am confused as to why this code is not working:
$.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();
在查看控制台,在点击分类链接之一,GET检索整个页面的响应,但随后是一个语法错误,无法识别的EX pression:(列出从中检索页面中的所有HTML )。所以,事情错在$ .fn.getFaqList,可能是使用$(数据)?
While viewing the console, upon clicking one of the category links, the GET retrieves the entire page in its response, but it is then followed by a Syntax error, unrecognized expression: (lists all HTML from retrieved page). So, something is going wrong in $.fn.getFaqList, possibly the use of $(data)?
有什么明显我做错了。任何帮助将大大AP preciated。我不是很精明与AJAX的东西。
Is there anything obvious I am doing wrong. Any help would be greatly appreciated. I am not very savvy with AJAX stuff.
感谢穆萨指出这一点。我会报答你的正确答案......但我想我不能这样做,要评论:(
Thanks to Musa for pointing this out. I would reward you as the correct answer... but I guess I can't do that to a comment :(
我不得不更换:
$(data).find
这一点:
$($.parseHTML(data)).find
我试过类似的事情之前,基于其他答案#1,但我不执行得当,所以我一直得到错误。对于任何人谁需要对这个问题更清楚,这些问题的答案可以帮助:
I had tried something similar before, based on other Stackoverflow answers, but I was not executing it properly so I kept getting the error. For anyone who needs more clarity on the issue, these answers might help:
JQuery未确认前pression对Ajax响应
jQuery 1.9 +客户端模板="语法错误,无法识别的EX pression"
上一篇:春季3 AJAX POST请求与@RequestBody和@ModelAttribute和@SessionAttribute一起使用?春季、AJAX、POST、SessionAttribute