Javascript 在XMLHttpRequest之后打开页面

Javascript 在XMLHttpRequest之后打开页面,javascript,http,post,get,xmlhttprequest,Javascript,Http,Post,Get,Xmlhttprequest,我在一个带有参数的页面上发布了XMLHttpRequest,在本例中为{file.nodeRef}。现在,我想打开相同的URL,但是使用post参数来访问它们。我怎样才能打开这一页 我的XMLHttpRequest的代码如下: var csrf_token = Alfresco.util.CSRFPolicy.getToken(); var http = new XMLHttpRequest(); var url = "hdp/ws/my-new-page";

我在一个带有参数的页面上发布了XMLHttpRequest,在本例中为{file.nodeRef}。现在,我想打开相同的URL,但是使用post参数来访问它们。我怎样才能打开这一页

我的XMLHttpRequest的代码如下:

    var csrf_token = Alfresco.util.CSRFPolicy.getToken();
    var http = new XMLHttpRequest();
    var url = "hdp/ws/my-new-page";

    var params = "file={"+file.nodeRef+"}";
    http.open("POST", url, true);
    //Send the proper header information along with the request
    http.setRequestHeader("Alfresco-CSRFToken", csrf_token);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");

    http.onreadystatechange = function() {//Call a function when the state changes.
        if(http.readyState == 4 && http.status == 200) {
            alert(http.responseText);
        }
    }
    http.send(params);

为什么不尝试使用ajaxjquery呢

$.ajax({
    type: "POST",
    url: "hdp/ws/my-new-page",
    beforeSend: function (request)
            {
                request.setRequestHeader("Alfresco-CSRFToken", csrf_token);
                request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                request.setRequestHeader("Content-length", params.length);
                request.setRequestHeader("Connection", "close");
            },
    data: "file={"+file.nodeRef+"}",
    dataType: "json",
    success: function(data) {
       window.location.href = data.redirect;       
    }
});

为什么要使用ajax jquery?@IvanStefanov你有其他解决方案吗?有人有其他解决方案吗?postGET或POST中的window.location参数丢失无法解决我的问题。。。我还有一个问题:但是,是的,对于OpenPage,这个代码可以工作。