Reputation: 1148
I have an ajax response code like the follows
function click_delete_reply(){
if ((ajMsgDel.readyState == 4) && (ajMsgDel.status == 200)) {
var restxt = ajMsgDel.responseText;
if (restxt == "success") {
location.reload();
display_messagesuccess(
"Message Delete has been successfully performed!");
}
}
}
I need to reload the page after ajax response success and then I need write a message in a 'div'. But here After message shown then only it performs the page load. What can I do to overcome this? Please help me!
Upvotes: 0
Views: 68
Reputation: 37876
Ok, fine, then try something likw this.
Before reload, attach some param to your url. With this, you can know in serverside if it was a reload from your ajax and return one more msg back like "reloaded". Then you do this:
$(function(){
//if the param in url is called "reloaded"
// then show message
});
$(function(){}); is the same as "DOM is ready"
Sorry i am in the bus, couldnot write much. Feel free to ask.
Upvotes: 1
Reputation: 2526
What you should do here is
1. Instead of Ajax Call give a server request and do the server side processing.
a) If the job is done successfully just send the message as the request parameter. Read that message and display where ever you want.
b) If the job fails then just return the values you need as response back to the page and display them where they should be.
Since a script is loaded everytime a page is loaded there is no way you can display a message by script message after the page is reloaded. You can either display the message and then reload page. or go with the way i mentioned above.
Upvotes: 0