2016-09-28 45 views
-1

数据从ajax调用成功检索。 在ajax成功,我需要重定向到'/帐户/索引',但重定向不工作在Ajax成功。 是否有任何替代window.location.href?页面重定向不适用于ajax成功的mvc

$.ajax({   
      url: "/Register/Register", 
      async: false, 
      type: "POST", 
      data: JSON.stringify(RegisterMember), 
      dataType: "json", 
      contentType: "application/json; charset=utf-8", 
      success: function (s) { 
       console.log(s); 
       //LoadprojectsGrid(); 
       // End For 


       if (s.MessageCode == 1) { 
        event.preventDefault(); 
        window.location.href = '/Account/Index'; 
       } 
       else if (s.MessageCode == 2) { 
        $('.cssload-loader').remove(); 
        $('#overlay').remove(); 
        $.growl.error({ message: s.Message }); 

       } 
       else 
       { 
        $('.cssload-loader').remove(); 
        $('#overlay').remove(); 
        $.growl.error({ message: s.Message }); 

       } 


      }, 
      error: function (jqXHR, textStatus, errorThrown) { 
       alert(errorThrown); 
       $('.cssload-loader').remove(); 
       $('#overlay').remove(); 
      } 
     }); 
+0

'window.location.href ='newUrl''应该工作。你确定你的if条件返回'true'吗? – Shyju

+0

是条件返回true – Ejazkhan

+0

根据W3C:window.location.href属性返回当前页面的URL。 –

回答

1

没有HREF:

了window.location = '/帐户/索引';

+0

如果你想使用分配方法: http://www.w3schools.com/js/js_window_location.asp –

0

尝试使用URL帮手如下:

window.location.href = '@Url.Action("Index", "Account")'; 
0

删除

event.preventDefault(); 

并使用

window.location = '/Account/Index'; as stated by @marcos 
相关问题