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!.
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.
Some sample code meant for the redirected view html: (I dont do php…)
Further reading: http://codeigniter.com/user_guide/libraries/sessions.html (half way down the page they mention flash data.)