$.when not waiting for Ajax request to finish

折月煮酒 提交于 2019-12-02 10:14:29

You need to return a jQuery Deferred object for $.when to work properly:

return article_view.save(viewDetails, 
    {
    success: function(data) {
            var count = data.get('count');   
            console.log('in saveView() success and count is ');
            console.log(count); 
            return count;     
        },
        error:   function(model, xhr, options){
           console.log(xhr.responseText);
        },
    });

Backbone's save() method returns a jqXHR object which behaves the same way as a Deferred object in this case. Simply chain the return call as above. This should get $.when() to wait for the request to finish.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!