[英]Javascript page redirection and session
我有注册javascript函数。 通过windiw.location函数重定向到用户(用户的私有页面)是否正确? 它将在会话范围内工作吗? 重定向请求时是否会附加httpcookie?
function signup()
{
var uName = document.forms[0].email.value;
var pass = document.forms[0].password.value;
var xmlhttp;
var response;
var url = "/v2/application/userlogin?fromClient=web&"+"email="+uName+"&password="+pass;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
response = xmlhttp.responseText;
//alert(response);
window.location = "/web/jsp/index.jsp?fromClient=web";
} else {
//document.getElementById("mainWindow").innerHTML = "Loading...";
//alert("loding");
}
};
xmlhttp.open("POST", url, true);
xmlhttp.send();
//alert(response);
}
从ajax回调中重定向是完全可以接受的。 但是,当请求受保护的页面时,在服务器端,您必须确保用户具有经过身份验证的会话,然后才能显示受保护的内容。
重定向请求时是否会附加httpcookie?
如果服务器响应包括一个新的cookie,则是,它将在出现window.location
请求时发送。
旁注:您应该使用encodeURIComponent()
对用户输入中的URL进行URL编码,以避免特殊字符破坏URL编码格式:
var url = "/v2/application/userlogin?fromClient=web&email="+ encodeURIComponent(uName)+"&password="+encodeURIComponent(pass);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.