Reputation: 1690
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);
Upvotes: 1
Views: 3002
Reputation: 479
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;
}
});
Upvotes: 3