2017-06-07 30 views
0

嗨,我已經嘗試了一些腳本,一旦顯示它就隱藏了閃存訊息,但它不起作用。顯示閃光訊息,直到我刷新頁面。在codeigniter中隱藏flash訊息幾秒後php

控制器:

if ($this->email->send()) 
     { 
      $this->session->set_flashdata('msg','<div class="alert alert-success text-center" id="successMessage">Thank you for contacting us we will get back to you soon!</div>'); 
      redirect('contact'); 
     } 
     else 
     { 
      $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>'); 
      redirect('contact'); 
     } 

查看:

<script> 
$(function() { 
// setTimeout() function will be fired after page is loaded 
// it will wait for 5 sec. and then will fire 
// $("#successMessage").hide() function 
setTimeout(function() { 
    $(".alert-success").hide('blind', {}, 500) 
}, 5000); 
}); 
</script> 
<div class="container"> 

<div class="row contactpageback"> 

     <div class="col-lg-6 contactuspagedetails"> 
      <form name="contact" id="contactform" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>contact"> 
      <?php echo $this->session->flashdata('msg');?> 
      <?php if(isset($msg)){?> 
      <?php echo $msg;?> 
       <?php } ?> 
+0

https://www.codeigniter.com/user_guide/libraries/sessions.html#flashdata這是怎麼fashdata作品。 –

+0

我們不能使用jquery來隱藏 – user8001297

+0

確定你可以但是關於flashdata它不能被自動刪除,直到刷新頁面。 –

回答

2

這是你想要的。希望這可以幫助你。

$(function() { 
 
// setTimeout() function will be fired after page is loaded 
 
// it will wait for 5 sec. and then will fire 
 
// $("#successMessage").hide() function 
 
    
 
    $(".hide-it").hide(5000); 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<html> 
 
<body> 
 
<div> 
 
    <h1 class='hide-it'>Flash Data value here</h1> 
 
</div> 
 
</body> 
 
</html>

0

控制器:

$this->load->library('session'); 
if ($this->email->send()) 
     { 
      $this->flash->success('Thank you for contacting us we will get back to you soon!</div>'); 
      redirect('contact'); 
     } 
     else 
     { 
      $this->flash->success('There is error in sending mail! Please try again later'); 
      redirect('contact'); 
     } 

查看:

<div id="mydivs"> 
     <?php echo $this->flash->display('success', TRUE);?> 
    </div> 
    <script> 
     setTimeout(function() { 
      $('#mydivs').hide('fast'); 
     }, 10000); 
    </script> 
1

這將幫助你隱藏你的消息3秒鐘fadeOut動畫後。 您可以更改timeout變量中的秒數。

var timeout = 3000; // in miliseconds (3*1000) 
 

 
$('.alert').delay(timeout).fadeOut(300);
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="alert alert-success"> 
 
    Success Message. 
 
</div>