See: AJAX query isn't functioning when passed a string for my previous question - that was resolved and this is a follow-up to another thing that is now confusing me.
My initial page loads, there's a drop-down menu, the user selects a name and that name is sent over to another page to load it inside of a DIV on the main page. This all works. There's an update button:
<form id="updateChanges" method="POST" action="update.php">
<input class="button" name="update"<?= $LineID ?>" type="submit" id="update" value="UPDATE">
and when it's clicked, it launches the JavaScript file to do the AJAX call without refreshing the entire page.
$(function() {
// Get the form.
var form = $('#updateChanges');
// Set up an event listener for the contact form.
form.submit(function(event) {
// Stop the browser from submitting the form.
event.preventDefault();
// Serialize the form data.
var formData = form.serialize();
// Submit the form using AJAX.
$.ajax({
type: 'POST',
url: form.attr('action'),
data: formData,
success: function() {
console.log("success!");
}
});
});
});
This works too.
What's confusing me now is how to get the "final page" to refresh and show the updates that the person has made to the database. I've tried a variety of things but everything is causing a full page refresh, which I can't have.
|_______________________________|
| ajaxtest.php |
| |
| _______#DIV____________ |
| | getuser.php | |
| | | |
| | | |
| |______________________| |
|_______________________________|
I need something inside of the success function that allows me to say "refresh getuser.php?q=John%Done inside of this DIV on ajaxtest.php" but nothing I've tried works.
I can't do something like this...
success: function () {
setTimeout("window.location = 'getuser.php'",100);
because the original string that I passed is not in this JavaScript file, and that only solves half my problem. If I just set the code to getuser.php?q=John%Doe
it works, but it loads THAT as the main page, not as a page inside the DIV on the primary page.
I'm lost as to how to solve this....