maddisoncr
asked on
Javascript callback
Hi
I know this is quite a basic question for anyone who has a good understanding of JavaScript.. I am playing catch up !
so basically.. call backs..
I have a form. The user clicks to edit or add a record. When he clicks update, I am displaying a message confirming the update. I then put them back to the main record list.
My idea was to show the message and then a call back to return to the list. I have got it a little backwards and it's basically showing at the same time..
Here's the code.. Thanks in advance
Main Form
I know this is quite a basic question for anyone who has a good understanding of JavaScript.. I am playing catch up !
so basically.. call backs..
I have a form. The user clicks to edit or add a record. When he clicks update, I am displaying a message confirming the update. I then put them back to the main record list.
My idea was to show the message and then a call back to return to the list. I have got it a little backwards and it's basically showing at the same time..
Here's the code.. Thanks in advance
Main Form
$.post($("#updateClientform").attr("action"),$("#updateClientform").serialize(),
function() {
fnUpdateSuccess('Client',function() {window.location.href = 'clients.php'});
}
);
Functionsfunction fnUpdateSuccess(fItemName, callback){
confirmationModal('Information','The '+fItemName+ ' has been succesfully Updated !');
if (callback) {
callback();
}
}
function confirmationModal(fTitle,fBody){
$('#confirmationModal').modal('show')
$('#confirmationModal .modal-title').html(fTitle)
$('#confirmationModal .modal-body').html(fBody)
}
ASKER
Sorry about the formatting and thank you for your comments, i will have a look now
ASKER
At present. I show a list of clients. The user then selects a client and a new php file is shown. This isn't through ajax.
When the user edits the client and updates it. I send the user back to the clients form. What i also want to do is show a modal box telling them that the update has been carried out. the user then clicks ok to dismiss.
At the moment, everything i've tried seems to load them both at the same time.
Hope that helps
When the user edits the client and updates it. I send the user back to the clients form. What i also want to do is show a modal box telling them that the update has been carried out. the user then clicks ok to dismiss.
At the moment, everything i've tried seems to load them both at the same time.
Hope that helps
$.post($("#updateClientfor m IS Ajax!
ASKER
I meant that I am not loading the new page through the ajax load.
But you are updating something using Ajax, then you load a page using window.location
If you instead just posted the form to the server and returned the new page, you would not have any issues
If you instead just posted the form to the server and returned the new page, you would not have any issues
ASKER
i understand what you are saying..
when i update the client.. i use a php file called updateclient.php. so is it a case of just using a header to load clients.php ?
when i update the client.. i use a php file called updateclient.php. so is it a case of just using a header to load clients.php ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The answer is dependent on how you call the post.
If in a submit button, you need to prevent the form from being submitted.
Open in new window
However I wonder why you would ever want to change the location if you use ajax to update the server.
If you need to reload the page, simply post the form and load the result