Javascript 就绪状态仍然是1,尽管我得到了响应

Javascript 就绪状态仍然是1,尽管我得到了响应,javascript,java,ajax,backbone.js,Javascript,Java,Ajax,Backbone.js,就绪状态仍为1,且函数中有。我使用的变量是一个窗口对象(returnValue)。当我在控制台(从chrome浏览器)再次打印对象时,它会显示就绪状态4,还允许我使用returnValue.responseText访问responseText。我正在使用backbone.js将输入保存到后端。返回已保存的responseText。但反过来,当我试图访问它时,我无法访问它,因为它表示未定义。如何获取此函数中所需的响应文本。主干的model.save()方法是异步的。它返回一个值(javascrip

就绪状态仍为1,且函数中有。我使用的变量是一个窗口对象(returnValue)。当我在控制台(从chrome浏览器)再次打印对象时,它会显示就绪状态4,还允许我使用returnValue.responseText访问responseText。我正在使用backbone.js将输入保存到后端。返回已保存的responseText。但反过来,当我试图访问它时,我无法访问它,因为它表示未定义。如何获取此函数中所需的响应文本。

主干的
model.save()
方法是异步的。它返回一个值(javascript xhr对象),但请求在返回时未完成

要使用完成的响应,通常需要将
success
error
回调传递给
save
方法():


当您习惯于从函数返回响应时,这可能是一种调整,但是使用回调几乎总是可以实现等效的功能。

谢谢,它起到了作用。因为数据不是JSON。我用了如下方法。this.model.save([],{dataType:“text”,success:function(response){returnValue=response.changed.Saved.xhr.responseText;console.log(returnValue);returnValue;},错误:function(){});
          toggleCompletedCheck : function(e) {
            e.stopPropagation();
            e.stopImmediatePropagation();
            var key = $(e.currentTarget).attr("id");
            this.model = todoCollection.findWhere({
                key : key
            });
            this.model.toggle("completed", true);
            this.option.collection = todoCollection.add(this.model);
            var email = this.model.get("email");
            var title = this.model.get("title");
            var key = this.model.get("key");
            var status = this.model.get("status");
            var completed = this.model.get("completed");
            this.updateUserData(email, key, title, completed, status);
            returnValue = this.model.save();
            console.log(returnValue);
        },
this.model.save(null, {
    success: function(model, response, options) {
        // do something with the response
    },
    error: function(model, response, options) {
        // do something with the response
    }
});