简体   繁体   中英

Open page after XMLHttpRequest

I made a XMLHttpRequest post to a page with params, in this case, {file.nodeRef}. Now, I want to open the same URL but with the post parameters to be able to access them. How can I open the page?

The code of my XMLHttpRequest is the following:

    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);

Why don't you try to use 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;       
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM