javascript - Ready state is still 1 though I got the Response -


          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);         }, 

the ready state still 1 in function. variable used window object(returnvalue). when print object again in console(from chrome browser) shows me ready state 4 allows me access responsetext using returnvalue.responsetext. using backbone.js save input backend. returns responsetext saved. in turn, unable access when try says undefined. how responsetext needed in function.

backbone's model.save() method asyncronous. returns value (the javascript xhr object), request not complete @ return time.

to use completed response, pass success or error callbacks save method (docs here):

this.model.save(null, {     success: function(model, response, options) {         // response     },     error: function(model, response, options) {         // response     } }); 

this can bit of adjustment when used returning responses functions, equivalent functionality possible using callbacks.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -