博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Jquery AJAX如何使用Promise/Deferred实现顺序执行?
阅读量:4507 次
发布时间:2019-06-08

本文共 581 字,大约阅读时间需要 1 分钟。

有的时候有我有N个AJAX请求,第下个请求可能要依赖上个请求的返回值, 可以用

$.ajax("test1.php").then(function(data) {// data 是 test1.php 的返回值return $.ajax("test2.php");}).then(function(data) {// data 是 test2.php 的返回值return $.ajax("test3.php");}).then(function(data) {return $.ajax("test4.php");});

  有的时候可以用when ,同时请求多个

function successFunc(){ console.log( “success!” ); }   function failureFunc(){ console.log( “failure!” ); }     $.when(      $.ajax( "/main.php" ),     $.ajax( "/modules.php" ),     $.ajax( “/lists.php” )   ).then( successFunc, failureFunc );

  

转载于:https://www.cnblogs.com/shenggen/p/5104879.html

你可能感兴趣的文章
20154313 刘文亨 EXP9
查看>>
快速排序
查看>>
Solidity的三种转账方式与比较
查看>>
js api 之 fetch、querySelector、form、atob及btoa
查看>>
php json_encode
查看>>
Docker系统四:Dcoker的镜像管理
查看>>
C#多线程---Semaphore实现线程同步
查看>>
.Net统计代码执行时间
查看>>
PHP连接MySQL报错:Fatal error: Call to undefined function mysql_connect()之解决方法
查看>>
postgre 二进制存储
查看>>
字符串kmp&exkmp&马拉车(刷题总结)
查看>>
什么是BFC
查看>>
【Java面试题】31 介绍Collection框架的结构
查看>>
Microsoft云备份解决方案Azure Backup的常见配置问题
查看>>
ConcurrentHashMap 的实现原理
查看>>
node中fs模块 - fs.open() fs.read() fs.write() fs.close()
查看>>
Java学习笔记_180713_TreeMap_Comparator重写
查看>>
ttt
查看>>
Finance_finacial_engineering_02
查看>>
抓取windows系统进程
查看>>