My goal is to send form data to the server without refreshing the page or displaying updated information. I am currently working with Firefox and exploring two approaches:
- By placing a button inside a form, I discovered that the form will be submitted as a "GET" request using the name of the page it's on. If I leave out the method attribute in the form tag and keep the action tag empty, I can input the desired function into the action attribute. However, after submitting the form, the browser replaces the original page with the response from the server.
- If I remove the button from the form and connect it directly to a JavaScript function, I can assign a function to the onreadystatechange event. This approach ensures that the function runs instead of reloading the page upon receiving a server response. The drawback here is that the function must independently formulate the "GET" request.
I believe there should be a way for the JavaScript function to instruct the form to submit using its own methods, while also being prepared to handle the response. As a newcomer to this technology, I'm unsure what the best practice would be in this scenario.