20151211jquery ajax进阶代码备份
//数据处理 $('form input[type=button]').click(function() { //json处理 /*$.ajax({ type:'POST', url:'test.json', dataType:'json', data:$('form').serialize(), success: function(response,status,xhr){ alert(response[0].url); } }); */ //本地获取jsonp.php成功 /*$.ajax({ type:'POST', url:'jsonp.php', dataType:'json', success: function(response,status,xhr){ alert(response.a); } });*/ //跨域获取jsonp.php,失败 /*$.ajax({ type:'POST', url:'http://www.li.cc/jsonp.php', dataType:'json', success: function(response,status,xhr){ alert(response.a); } });*/ //本地获取jsonp2.php成功 /*$.getJSON('jsonp2.php?callback=?',function(response){ alert(response.a); });*/ //跨域,远程,成功 /*$.getJSON('http://www.li.cc/jsonp2.php?callback=?',function(response){ alert(response.a); });*/ /*$.ajax({ type:'POST', url:'jsonp2.php', dataType:'jsonp', success: function(response,status,xhr){ alert(response.a); } });*/ //jqXHR对象 //jqXHR就是$.ajax 返回的对象 /*var jqXHR=$.ajax({ type:'POST', url:'user.php', data:$('form').serialize() });*/ //alert(jqXHR); /*jqXHR.success(function(response){ alert(response); });*/ /*jqXHR.done(function(response){ alert(response+'1'); }).done(function(response){ alert(response+'2'); });//可以连缀操作 jqXHR.done(function(response){ alert(response+'3'); });*/ var jqXHR=$.ajax('t1.php'); var jqXHR2=$.ajax('t2.php'); /*jqXHR.done(function(response){ alert(response); }); jqXHR2.done(function(response){ alert(response); });*/ $.when(jqXHR,jqXHR2).done(function(r1,r2){ alert(r1[0]); alert(r2[0]); }); });