2011-01-13 55 views
0

'选择'操作由XmlHttpRequest调用。为什么浏览器不能重定向虽然提琴手显示相反

$.ajax(
      { 
       async: false, 
       url: 'Project/Select/1'      
      }); 

“选择”作用,使重定向

[HttpPost] 
    public ActionResult Select(core_User user) 
    { 
     int id = 0; 
     if (int.TryParse(this.RouteData.Values["id"].ToString(), out id)) 
     { 
      Project.Load(id); 
      return Redirect("~/general-settings")); 
     } 
     return new EmptyResult(); 
    } 

在菲德勒我看到重定向请求被发送,但浏览器不会使重定向。它停留在前一页上。

这是REDIRECT请求的RAW。

GET http://localhost:26838/general-settings HTTP/1.1 
Host: localhost:26838 
Connection: keep-alive 
Referer: http://localhost:26838/project-manager 
X-Requested-With: XMLHttpRequest 
Accept: application/json, text/javascript, */* 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) 
Chrome/8.0.552.237 Safari/534.10 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 
Cookie: ASP.NET_SessionId=t2242xxnk4bf0qk0gkvyrji2 

问题在哪里?

+3

您正在使用XMLHTTPRequest并希望浏览器更改您所在页面的网址?这不是它的工作原理。 – 2011-01-13 16:56:49

回答

0

我建议你follow this example对一个类似的Stackoverflow问题。

它向您显示如何在重定向的情况下使用$.ajax。注意事实是,使用window.location.replace()代替直接设置位置更好。

相关问题