weixin_33709364 2013-09-11 15:43 采纳率: 0%
浏览 6

Ajax / php标头:位置

I have a Bootstrap modal with an Ajax login form. Displaying errors and everything works just fine until the result from login.php is header('Location: index.php');

I handle the result like this:

var hr = new XMLHttpRequest();
    // Set content type header information for sending url encoded variables in the request
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    // Access the onreadystatechange event for the XMLHttpRequest object
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var return_data = hr.responseText;
            document.getElementById("status").innerHTML = return_data;
        }
    }

The problem is that when the login is successful and I get the header('Location: index.php'); response index.php is opened in div.status.

Is there an easy way to translate the PHP header to a redirect in javascript?

  • 写回答

2条回答 默认 最新

  • 普通网友 2013-09-11 15:47
    关注

    You should use javascript to rewrite the document.location instead of sending a HTTP header. It will give the user the same basic experience as a traditional redirect response from a full page request.

    评论

报告相同问题?