gpt4 book ai didi

javascript - 如何从 xhrpost 函数检索响应数据并将该对象存储在 dojo/store 中?

转载 作者:行者123 更新时间:2023-12-02 18:02:11 25 4
gpt4 key购买 nike

我已使用 REST 创建了一个登录名和 Dojo 。我正在使用 dojo xhrpost 提交我的登录表单数据。提交是通过 onClick 函数执行的。响应是从剩余方法返回的。如何将响应对象存储在 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 请求,否则必须在 session 数据中传递数据。

关于javascript - 如何从 xhrpost 函数检索响应数据并将该对象存储在 dojo/store 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20425089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com