开发者

Why browser DOESN'T make the redirect though Fiddler shows the opposite

The 'Select' action is called by XmlHttpRequest.

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

The 'Select' action makes redirect

[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();
    }

In Fiddler I see that redirect request is sent, BUT, the browser DOESN'T make the redirect. It stays on the previous page.

Here is the RAW of the REDIRECT request.

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) A开发者_如何学GoppleWebKit/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

Where is the problem?


I suggest you follow this example on a similar Stackoverflow question.

It shows you how to use $.ajax in redirect situation. Mind the fact that it is better for you to use window.location.replace() instead of setting location directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜