angularjs – 如何在角度js中进行同步http请求
发布时间:2020-12-17 08:08:46 所属栏目:安全 来源:网络整理
导读:如何在角度js中阻止http请求,以便我可以在角度js中的下一行使用$ http响应。 这里$ http对象不会在下一行返回结果,以便我可以在fullcalender上传递一个javascript库的$ http响应。 这里$ scope.data返回空值。 下面的示例代码 $http.get('URL').success(fu
如何在角度js中阻止http请求,以便我可以在角度js中的下一行使用$ http响应。
这里$ http对象不会在下一行返回结果,以便我可以在fullcalender上传递一个javascript库的$ http响应。 这里$ scope.data返回空值。 下面的示例代码 $http.get('URL').success(function(data){ $scope.data = data; }); $.fullCalender({ data: $scope.data });
您可以使用
promises。
这里是一个例子: $scope.myXhr = function(){ var deferred = $q.defer(); $http({ url: 'ajax.php',method: 'POST',data:postData,headers: {'Content-Type': 'application/x-www-form-urlencoded'} }) //if request is successful .success(function(data,status,headers,config){ //resolve the promise deferred.resolve('request successful'); }) //if request is not successful .error(function(data,config){ //reject the promise deferred.reject('ERROR'); }); //return the promise return deferred.promise; } $scope.callXhrAsynchronous = function(){ var myPromise = $scope.myXhr(); // wait until the promise return resolve or eject //"then" has 2 functions (resolveFunction,rejectFunction) myPromise.then(function(resolve){ alert(resolve); },function(reject){ alert(reject) }); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- webservice详解
- 单元测试 – Karma不执行任何单元测试
- 哈希位置策略不起作用 – Angular 4 – NgxChartsModule打破
- angularjs – Angular JS UI Bootstrap选项卡(ui.bootstrap
- angularjs – 如何更改ng-tags-input separator? (默认:破
- 参考/etc/rc.d/init.d/smb编写的单Tomcat起停rc脚本
- scala – 在Int => Int = _ 1 中_的用法是什么
- Angular CLI – 获取覆盖率报告以包含所有来源
- bootstrap1
- bash – 使用sed / awk打印具有匹配模式的行或另一种匹配模