MsKazza Posted August 12, 2016 Share Posted August 12, 2016 Hi, I have been reading up on ajax using jquery, and theres something I can't seem to find, i have a form that gets the field values from mysql when the page loads, what is the best way to use ajax to edit this form? Obv the ajax request will execute the mysql update statement but how do i get the edited data back into the form, ready to be worked with again. thanks, hope i made sense, just looking for a little direction. MsKazza Quote Link to comment https://forums.phpfreaks.com/topic/301867-editing-prepopulated-form/ Share on other sites More sharing options...
Solution Jacques1 Posted August 12, 2016 Solution Share Posted August 12, 2016 Why do you need to get data back into the form? If you use Ajax, the form content doesn't get deleted at all (unless you do that yourself). Quote Link to comment https://forums.phpfreaks.com/topic/301867-editing-prepopulated-form/#findComment-1536028 Share on other sites More sharing options...
MsKazza Posted August 12, 2016 Author Share Posted August 12, 2016 Oh right, so whatever is typed into the form basically just stays there? Ajax just executes the update statement and leaves the page alone. So in theory i edit a product description, click submit, it executes the update, then i see an error correct it, submit again and again it executes the update while the page stays as I typed it. **lightbulb moment** I thought it was somehow refreshing the page without reloading. In that case If i'm adding something to a mysql table via a form and have the results displayed in a separate div, how is this updated to reflect the new information, do i somehow need to make the div reload? Thanks very much for the quick response. Quote Link to comment https://forums.phpfreaks.com/topic/301867-editing-prepopulated-form/#findComment-1536029 Share on other sites More sharing options...
Jacques1 Posted August 12, 2016 Share Posted August 12, 2016 Ajax simply means that JavaScript makes additional HTTP requests in the background. The page content isn't affected by this in any way. If you want to update parts of the page, you have to do that yourself with JavaScript. For example, if the div element has the ID “status”, then $('#status').text('Success'); will change the text content of the element to “Sucess”. Generating complex HTML structures like lists is more difficult. If you have a specific question, post your code. Quote Link to comment https://forums.phpfreaks.com/topic/301867-editing-prepopulated-form/#findComment-1536031 Share on other sites More sharing options...
MsKazza Posted August 12, 2016 Author Share Posted August 12, 2016 No thank you you have sent me in the right direction, I get it now. Once its updated can send message to page such as 'record updated' but the actual page will stay the same. Thanks very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/301867-editing-prepopulated-form/#findComment-1536032 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.