【问题标题】:How to retrieve response data from xhrpost function and store that object in dojo/store?如何从 xhrpost 函数中检索响应数据并将该对象存储在 dojo/store 中?
【发布时间】:2013-12-06 13:26:41
【问题描述】:

我使用RESTDojo 创建了一个登录名。我正在使用dojo xhrpost 提交我的登录表单数据。提交是通过 onClick 函数执行的。响应从 rest 方法返回。如何将响应对象存储在诸如dojo/Memory 的dojo/store 中?这样我就可以在任何 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";                                                
        }
    }
});

【问题讨论】:

    标签: javascript dojo


    【解决方案1】:

    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 请求,否则您必须在会话数据中传递数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多