简体   繁体   English

Codeigniter使用jQuery显示表单成功消息?

[英]codeigniter show form success message using jquery?

new to CI and trying to figure out how to put it all together. CI的新功能,并试图弄清楚如何将它们组合在一起。 I have a form that i'm submitting via the form helper and using the form validation library to send feedback to the user. 我有一个要通过表单助手提交的表单,并使用表单验证库将反馈发送给用户。 I'm submitting the form with a simple $('#editForm').submit(); 我用一个简单的$('#editForm').submit();

I'd like to be able to show a success notification to the user and use jquery animations to make it appear in a smooth transition versus just showing up. 我希望能够向用户显示成功通知,并使用jquery动画使它以平滑的过渡而不是仅仅显示。

All I've been able to do so far is use flashdata to conditionally display the div containing the notification in the view file. 到目前为止,我所能做的就是使用flashdata在视图文件中有条件地显示包含通知的div。

  <div id="success-alert" style="display:none;" class="alert alert-success alert-dismissable">
      <button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>
      Success!
</div>

Is there a way to trigger jquery to animate this? 有没有一种方法可以触发jquery对此进行动画处理? I tried just echoing out some php to conditionally display the jquery code, but it wasn't working: 我尝试仅回显一些php来有条件地显示jquery代码,但是它不起作用:

<?php if($this->session->flashdata('result') == 'success') { ?>
  $('#success-alert').slideDown('slow');
  setTimeout(function() {$('#success-alert').slideUp('slow');}, 2100);
<?php }; ?>

I get this error: Uncaught SyntaxError: Unexpected token < 我收到此错误:未捕获的SyntaxError:意外的令牌<

I'd prefer not to use flashdata, other than to conditionally execute jquery, if possible. 我宁愿不使用flashdata,而是尽可能地有条件地执行jquery。 I know there must be a way, but unfortunately too I'm new to CI to know what it is. 我知道一定有办法,但不幸的是,我也是CI的新手,不知道它是什么。

you dont have to check the value of flash data if the flash data is set then it will trigger 您不必检查闪存数据的值(如果已设置闪存数据),它将触发

<?php if($this->session->flashdata('result')) { ?>
  <script>
    $('#success-alert').slideDown('slow');
    setTimeout(function() {$('#success-alert').slideUp('slow');}, 2100);
  </script>
<?php }; ?>

Note this should be in same page where your form redirects after success. 请注意,这应该在表单成功后重定向到的同一页面中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM