Best approach to update a control after an Ajax request?
Posted
by Cuga
on Stack Overflow
See other posts from Stack Overflow
or by Cuga
Published on 2010-05-25T03:58:56Z
Indexed on
2010/05/25
4:01 UTC
Read the original article
Hit count: 188
I have a webpage that fires off an Ajax request which stores some data to a database and I want to update the webpage so that the user can see their changes have been submitted.
There are at least 3 ways I can think of accomplishing this:
- Immediately update the webpage with plain JavaScript by grabbing the contents of the user's inputted text and immediately inserting it where it belongs.
- Have the ajax call return the stored text as the response, grab the response, and then insert this text where it belongs on the page using JavaScript
- Have the ajax call return a flag (say, true for successful db write, false otherwise), and if the flag is true, use JavaScript to grab the user's contents from the input control and insert it where it belongs elsewhere on the page
- Or another method not mentioned...?
I don't mean this to be subjective, I just don't know which would be the best method to apply. My instinct tells me to go with the third item (return a flag, then update the field). Is this the best way?
Thanks
© Stack Overflow or respective owner