2017-11-16 8 views
0

私はボタンをクリックして.toggle機能で表示されるCSS表示なしのdivを持っています。jQuery .load div insideトグル

そのdivにはブログのコメントが含まれています。私が新しいコメントを送るとき、.load機能でそのdivをリフレッシュしますが、divをトグルするので、再びボタンをクリックして表示する必要があります。

これを避ける方法はありますか?

CSS:

.comments-container { 
    width: 100%; 
    display: none; 
} 

HTML:

<div class="row" id="criticas-wrapper"> 
    <h4 class="media-title" id="toggle_criticas" onclick="ver_criticas()">&#x25BC CRÍTICAS</h4> 
    <button type="button" class="reply">Nuevo comentario</button> 
    <div class="comments-container"> 
    // Here are all the comments 
    </div> 
</div> 

JSは:

<script> 
    function ver_criticas() { 
     $(".comments-container").toggle("slow"); 

    } 
</script> 

<script> 

    jQuery(document).on('submit', '.comment_form', function(e){ 
    event.preventDefault(); 

$.ajax({ 

type: "POST", 
url: $(this).attr("action"), 
data: $(this).serialize(), 

success:function(data){ 
var json = JSON.parse(data); 

     $(".errormensaje,.correctomensaje").html("").css({"display":"none"}); 


$("#comment").val(""); 
    $('#parent_comment').val(""); 


if(json.resultado =="correcto"){ 

    if(json.mensaje){ 
var notification = alertify.notify('¡Mensaje publicado!', 'success', 3, function(){ console.log('dismissed'); }); 
$('#criticas-wrapper').load('<?php echo base_url(uri_string());?> #criticas-wrapper'); 


    } 

} 
if(json.resultado =="error"){ 

    if(json.mensaje){ 
     //$(".errormensaje").append(json.mensaje).css({"display":"block"}); 
     var notification = alertify.notify(json.mensaje, 'error', 3, function(){ console.log('dismissed'); }); 

    } 

} 
else 
{ 
console.log(data); 
} 
}, 
error:function(xhr,exception) 
{ 

} 
}) 
e.preventDefault(); 


    }); 

</script> 
+1

あなたがやっていることを見せてくれればいいですか? – funcoding

+0

あなたはコードを表示する必要がありますか? – user3154108

+0

私の推測では、負荷が再びdivを隠しているということです!ロード後、イベントをトリガして表示する必要があります。または、CSSの表示属性を変更します。 – funcoding

答えて

1

最も簡単な方法は、あなたがそれをリロードした後だけdivshow()を追加することです。

...load(url, function(){ 
    ...show(); 
}) 

ロード完了後すぐに表示されます。

+0

私は同様のものを試しました。( ".comments-container")。toggle( "slow"); .loadの後に.load関数に少しの遅延がある場合は、まずそれをトグルしてロードして、同じポイントになるようにします。 – Trakemys

+0

もう一度私のコメントを編集して、私の言いたいことを教えてあげます。 –