成功ajax调用后重定向消息

时间:2016-04-15 07:32:21

标签: jquery ajax

当功能成功将用户重定向到索引页面以在删除成功的页面上显示消息时如何制作?到目前为止,我只能重定向用户

$.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); 
   }             
});         

2 个答案:

答案 0 :(得分:1)

更改window.location.href = 'index.php#lessondelete';

在您的索引页面中:

$(function(){
var hash = window.location.hash
if(hash == "#lessondelete") {
  alert('You successfully deleted this Lesson!'); 
//$('body').prepend('<p>You successfully deleted this Lesson</p>')
}
});

答案 1 :(得分:0)

除了接受的答案:

接受答案的唯一问题是添加的#text不会从网址中删除,如果我们刷新页面,则会再次显示成功消息。因此,要避免页面刷新消息,请使用下面的示例代码更改URL

history.pushState({},"URL Rewrite Example","https://stackoverflow.com/example")

但您只能在支持它的浏览器中执行此操作。按照您的意愿更改网址后,请尝试以上行;在您的浏览器JavaScript-Console

相关问题