2013-07-21 74 views
0

我试图使用before()显示ajax请求的结果。它工作得很好,但现在我想用动画(切换,滑动或其他)显示结果。jquery之前()动画

这里是我使用的代码:

jQuery.ajax({ 
      type: "POST", 
      url: "/postcom", 
      dataType:"text", 
      data:myData, 
      success:function(response){ 
      $("#results_com").before(response); 
      $("#formcomtext").val(''); 
         }, 
      error:function (xhr, ajaxOptions, thrownError){ 
       console.log(thrownError); 
      } 
     }); 

HTML:

<div id="results_com></div> 

感谢

回答

0

如果使用insertBefore,它可能是更容易:

$(response).insertBefore("#results_com").animate({}, 400); 
+0

不工作...它仍然会出现在一个镜头...... – Recif

+0

插入后试试'.hide()'。我只是给你一个让链条继续前进的方式,而不必穿越新的dom。或者,使用CSS来隐藏任何“结果”,并使用jquery为其设置动画。 – kalley

+0

我尝试了$(response).insertBefore(“#results_com”)。hide()。animate({},400);但现在它不再工作了(没有什么是由AJAX插入的) – Recif

0

你应该只是隐藏前在其动画下面是它一个简单的演示:http://jsfiddle.net/pERgk/

+0

不起作用...它仍然出现在一个镜头中... – Recif

+0

不,它不。当你在页面上时点击“运行”。它很快就会发生。 –

+0

是的,我知道,我谈到了我的网页。它不适用于$('#results_com')。append(response).fadeIn('slow'); – Recif

0

工作演示http://jsfiddle.net/cse_tushar/pERgk/2/

可以使用toggle代替slideDown

$('#results_com').click(function() { 
    $('#results_com').hide().before('This will be the result').slideDown('slow'); 
}); 
+0

不起作用...它仍然出现在一个镜头中...... – Recif

+0

你试过了什么代码ID?我测试了它的工作原理 –

+0

jQuery.ajax({ 类型: “POST”, URL: “/邮”, 数据类型: “文本”, 数据:myData的, 成功:函数(响应){ $('# ('#formcom'); hide()。before(response).slideDown('slow'); $(“#formcom”)。toggle('slow'); $(“#formcomtext”).val('') ; \t \t \t \t \t \t}, 错误:功能(XHR,ajaxOptions,thrownError){ 的console.log(thrownError); } }); – Recif

相关问题