我有以下块:

$('.new_comment').live('ajax:success', function(evt, data, status, xhr){
  $('.comments article:last').after(xhr.responseText).effect("highlight", {}, 3000);
})


因此,在提交new_comment表单时,它将调用此表单。

after()函数工作正常,但是effect()调用引发此错误:

TypeError: 'undefined' is not a function (evaluating '$('.comments article:last').after(xhr.responseText).effect("highlight", {}, 3000)')


我正在使用jQuery 1.7.1和jQuery UI 1.8.16。

更新:xhr.responseText返回一个新创建的article元素,如下所示:

<article id="2">
  <h6><a href="#">Joe</a> <span>(<a href="#2">less than a minute ago</a>)</span></h6>
  <p>This is the new comment!</p>
</article>


添加后,.comments DOM如下所示:

<section class="comments">
  <h3>Comments</h3>
  <article id="1">
    <h6><a href="#">Joe</a> <span>(<a href="#1">less than a minute ago</a>)</span></h6>
    <p>This is a comment!</p>
  </article>
  <article id="2">
    <h6><a href="#">Joe</a> <span>(<a href="#2">less than a minute ago</a>)</span></h6>
    <p>This is the new comment!</p>
  </article>
</section>


另外,如果我运行console.log($('.comments article:last'));,它肯定会返回创建的对象。

最佳答案

我解决了这个问题。我两次加载了jQuery库。曾经与Rails一起使用预捆绑的版本,一次来自Google的CDN。删除其中之一,现在一切正常。叹。

10-05 20:49
查看更多