dsxrq28228 2012-07-04 02:09
浏览 42
已采纳

显示“成功”或“错误”jquery对话框的好方法是什么?

I'm using PHP CodeIgniter with jQuery.

Say for example I have a <table> (of employees perhaps). Now above the said table I have an "Add Employee" button. This button opens a jQuery-dialog with the <form>. When this form submits, it goes server-side of course (validates whether a duplicate entry or not), then it's sent back to corresponding view with the updated table.

What I want to do is to show a dialog that an employee is successfully added or that it is a duplicate entry.

I'm doing this by

appname/controller/action?addSuccess=true

or

appname/controller/action?addSuccess=false

everytime I return back to the view, then on my page, in my $(document).ready() I check for such query string and opens the corresponding dialog (success or error dialog). My problem now is that, if I refresh the page (same url) I get the dialogs again (although nothing happens serverside).

QUESTION: Is this approach good enough? Any good advice to improve this? :)

Thanks a lot!.

  • 写回答

1条回答 默认 最新

  • douying0108 2012-07-04 02:49
    关注

    Instead of passing that info as a query parameter, why not store that info Code Igniters flash data. This data gets persisted across only one redirect. The next time you reload the page, the data will not be set (as CI will automatically remove it for you) and you wouldnt accidentally display the warning.

    • Form is submitted to server. Set appropriate value in CI's flash message system.
    • Redirect to another url? Or maybe display another view.
    • In the view html, use php to read that flash message value and set an appropriate value in javascript.
    • Read that js value and accordingly display the popup/modal/message.
    • The flash message data will be removed automatically by CI at next page refresh.

    Some sample code meant for the redirected view html: (I dont do php...)

    var shouldDisplayWarning = "<? php code that sets some value based on flash variable ?>";
    if (shouldDisplayWarning === "yes") {
      displayWarning();
    }
    

    Further reading: http://codeigniter.com/user_guide/libraries/sessions.html (half way down the page they mention flash data.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来