<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(function(){
$("#clickBtn").on("click",function(){
getData(0,10);//输出0-9
})
})
function getData(i,length){
$.ajax({
type:"post",
url:"setDeffer.php",
data:{
data:i
},
async:true,//异步
success:function(data){
$("#showArea").text($("#showArea").text()+data+"\n");
if(i<length-1){
getData(i+1,length);
}
}
});
}
</script>
<?php $str = $_POST["data"]; sleep(1);//延迟1秒 echo "输出".$str; ?>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(function(){
$("#clickBtn").on("click",function(){
recycleData(0,10);//输出0-9
})
})
function getData(i){
var defer = $.Deferred();
$.ajax({
type:"post",
url:"setDeffer.php",
data:{
data:i
},
async:true,//异步
success:function(data){
$("#showArea").text($("#showArea").text()+data+"\n");
defer.resolve(data);
}
});
return defer.promise();
}
function recycleData(i,length){
$.when(getData(i)).done(function(data){//这里的data为defer在ajax保存下来的数据
if(i<length-1){
recycleData(i+1,length);//递归
}
})
}
</script>
function successFunc(){ console.log( “success!” ); }
function failureFunc(){ console.log( “failure!” ); }
$.when(
$.ajax( "/main.php" ),
$.ajax( "/modules.php" ),
$.ajax( “/lists.php” )
).then( successFunc, failureFunc );
$.when($.ajax("test1.html"), $.ajax("test2.html"))
.done(function(){ alert("哈哈,成功了!"); })
.fail(function(){ alert("出错啦!"); });
var defereds = []; //定义一个数组存放Deferred对象
$imgs.each(function() { //imgs循环所有图片
var dfd = $.Deferred();// 新建一个deferred对象
$(this).load(dfd.resolve());// 图片加载完成之后,改变deferred对象的执行状态
defereds.push(dfd);//push到数组中
});
$.when.apply(null, defereds).done(function() {
console.log('load compeleted');
});
function prints(a,b,c,d){
console.log(a+b+c+d);
}
function example(a,b,c,d){
prints.apply(this,[a,b,c,d]);
}
example("1","sd","wq","wqe") //输出:1sdwqwqe
prints.apply(null,["脚","本","之","家"]);//输出:编程素材网
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有