ajax 详解
1.url:要求为 2.type:要求为 3.timeout:要求为 4.async:要求为 注意:同步请求将锁住浏览器,用户其他操作必须等待请求完成才可以执行。 5.cache:要求为Boolean类型的参数,默认为 6.data:要求为 7.dataType:要求为
eg: 8.beforeSend:要求为 function(XMLHttpRequest){
this; //调用本次ajax请求时传递的options参数
}
9.complete:要求为 function(XMLHttpRequest,textStatus){
this; //调用本次ajax请求时传递的options参数
}
10.success:要求为Function类型的参数,请求成功后调用的回调函数,有两个参数。(1)由服务器返回,并根据dataType参数进行处理后的数据。 (2)描述状态的字符串。 function(data,textStatus){//data可能是xmlDoc、jsonObj、html、text等等
this; //调用本次ajax请求时传递的options参数
}
eg: success : function(data) {
var map = new Map();// 自定义map结构,参考mil.underwrite.public.js
var phaseroundjson = {};
phaseroundjson.percent = false;
phaseroundjson.name = '项目数';
phaseroundjson.percent = false;
phaseroundjson.color = [ 'jasper','Cyan','Khaki','yellow','pink','green','gray','blue' ];
phaseroundjson.data = [];
// 遍历数组
for (var i = 0; i < data.length; i++) {
// 填充饼状图数据
phaseroundjson.data.push([ data[i].phaseName,data[i].itemCount ]);
}
phaseroundjson.click = function(e) {
// 设置表格数据title
$("#showpath").html($("input[name='feeType']:checked").next("span").text() + '险种 <i class="fa fa-angle-right" title="右"></i> ' + e.point.name);
// 展示环节所有项目信息
loadTrackItemByFeeTypeAndPhase(map.get(e.point.index),"");
};
11.error:要求为 function(XMLHttpRequest,textStatus,errorThrown){
//通常情况下textStatus和errorThrown只有其中一个包含信息
this; //调用本次ajax请求时传递的options参数
}
12.contentType:要求为 13.dataFilter:要求为 function(data,type){
//返回处理后的数据
return data;
}
14.dataFilter: function(data,type){
//返回处理后的数据
return data;
}
15.global:要求为Boolean类型的参数,默认为true。表示是否触发全局ajax事件。设置为false将不会触发全局ajax事件,ajaxStart或ajaxStop可用于控制各种ajax事件。 16.ifModified:要求为Boolean类型的参数,默认为false。仅在服务器数据改变时获取新数据。服务器数据改变判断的依据是Last-Modified头信息。默认值是false,即忽略头信息。 17.jsonp:要求为String类型的参数,在一个jsonp请求中重写回调函数的名字。该值用来替代在” 18.username:要求为String类型的参数,用于响应HTTP访问认证请求的用户名。 19.password:要求为String类型的参数,用于响应HTTP访问认证请求的密码。 20.processData:要求为Boolean类型的参数,默认为true。默认情况下,发送的数据将被转换为对象(从技术角度来讲并非字符串)以配合默认内容类型” 21.scriptCharset:要求为String类型的参数,只有当请求时dataType为”jsonp”或者”script”,并且type是GET时才会用于强制修改字符集(charset)。通常在本地和远程的内容编码不同时使用。 $(function(){
$('#send').click(function(){
$.ajax({
type: "GET",url: "test.json",data: {username:$("#username").val(),content:$("#content").val()},dataType: "json",success: function(data){
$('#resText').empty(); //清空resText里面的所有内容var html = '';
$.each(data,function(commentIndex,comment){
html += '<div class="comment"><h6>' + comment['username']
+ ':</h6><p class="para"' + comment['content']
+ '</p></div>';
});
$('#resText').html(html);
}
});
});
});
22.顺便说一下$.each()函数:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |