我已经用REST和Dojo创建了一个登录名。我正在使用dojo xhrpost提交我的登录表单数据。提交通过onClick功能执行。响应是从rest方法返回的。如何将响应对象存储在dojo/store(如dojo/Memory)中?这样,我就可以在任何html页面中检索它,并删除注销对象。
dojo.xhrPost({
url: "http://localhost:8080/userservices/rest/rest/login",
form: dojo.byId("formNode"),
load: function(user,status) {
if(status.xhr.status == 200) {
alert(user); //---> which displays username from the response method in rest method
// What code for could be here for storing that user as an object to dojo store or memory to access several pages and delete the object?
window.location.href ="jobseekerdashboard.html";
}
}
});
dojo.xhrPost已弃用。看看dojo/request/xhr。
require(["dojo/request/xhr", "dojo/store/Memory"], function(xhr, Memory){
xhr("http://localhost:8080/userservices/rest/rest/login", {
method: "POST",
data: dojo.byId("formNode")
}).then(function(returnedData){
new Memory({
data: returnedData
});
window.location.href= "jobseekerdashboard.html";
}, function(err){
// Handle the error condition
}
});
如果你改变窗口的位置,你将失去当前的环境。如果您想更改页面位置,则必须在页面加载后发出一个新的ajax请求,或者必须传递会话数据中的数据。