Reputation:
How to make it when function success redirect user to index page to show message on the page that deletion was successful? So far I was able only to redirect user
$.ajax({
type: 'get',
url: 'lessonDel.php',
data: 'ajax=1&delete=' + upload_id,
success: function()
{
window.location.href = 'index.php';
//alert('You successfully deleted this Lesson! Status = ' + xhr.status);
}
});
Upvotes: 3
Views: 2585
Reputation: 1421
In addition to accepted answer:
The only problem with the accepted answer is the added #text will not be removed from the URL and if we refresh the page the success message will appear again. So to avoid the message on page refresh change the URL by using the sample code below
history.pushState({},"URL Rewrite Example","https://stackoverflow.com/example")
But you can do it only in browsers that support it. Just try the above line after changing the URL as per your; in your browsers JavaScript-Console
Upvotes: 0
Reputation: 32354
change window.location.href = 'index.php#lessondelete';
in your index page :
$(function(){
var hash = window.location.hash
if(hash == "#lessondelete") {
alert('You successfully deleted this Lesson!');
//$('body').prepend('<p>You successfully deleted this Lesson</p>')
}
});
Upvotes: 2