ajax 异步问题

PhysicianManagement.prototype.listPhysician = function() {
    alert(JSON.stringify(this.physicianList));  // {}
    alert(JSON.stringify(this.physicianRelList)); // {}
};

PhysicianManagement.prototype.initProviderInfo = function() {
    ajaxCallForEventWithJsonData(this,'fetchProviderInformation',null, null, function (that,data) {
        that.physicianList = data;
    });
    ajaxCallForEventWithJsonData(this,'fetchProviderRel',null, null, function (that,data) {
        that.physicianRelList = data;
    });
    ajaxCallForEventWithJsonData(this,'fetchLoginUserInformation',null, null, this.initLoginUserInformation);
//由于异步,这里在数据还未请求结束就已经执行了
this.listPhysician(); };

 

解决办法

ajaxCallForEventWithJsonData(this,'fetchProviderInformation',null, null, function (that,data) {
        that.physicianList = data;
        ajaxCallForEventWithJsonData(that,'fetchProviderRel',null, null, function (innerThat,data) {
            innerThat.physicianRelList = data;
            innerThat.listPhysician();
            ajaxCallForEventWithJsonData(innerThat,'fetchLoginUserInformation',null, null, innerThat.initLoginUserInformation);
        });
    });
posted @ 2014-09-05 13:47  廖东海  阅读(287)  评论(0编辑  收藏  举报