$http({
url: "php/load.php",
method: "GET",
params: {'userId':userId}
}).success(function(data, status, headers, config) {
$scope.data = data;
}).error(function(data, status, headers, config) {
});
$scope.data[0]= "something";
如何等待ajax完成加载然后加载$scope.data[0]=“something”;?我尝试将其放置在 $http 内和 $scope.data=data 下方,但似乎仍然存在冲突..
最佳答案
var promise1 = $http({
url: "php/load.php",
method: "GET",
async: false,
params: {'userId':userId}
});
$.when(promise1).then(
function(data, status, headers, config) {
$scope.data = data;
},
function(data, status, headers, config) {
}
).done(function() {
$scope.data[0]= "something";
});
还没测试过,不过应该是对的。查看jQuery.when()和 jQuery.promise()如果没有。
关于javascript - 异步模式下ajax回调冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23579147/