在 XMLHttpRequest 之后打开页面
Open page after XMLHttpRequest
我向带有参数的页面发出了 XMLHttpRequest post,在本例中为 {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;
}
});
我向带有参数的页面发出了 XMLHttpRequest post,在本例中为 {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;
}
});