Ajax方法及常用属性

$(# id).click(funtion(){
$.ajax{
type:"post",
data:{name: $(#id) .val() },
async:"true",//默认 异步提交
traditional:true, //表示传递的是数组
dataType:"text",//预期服务器返回的数据类型 String,text,json,xml,html,script,
contentType: 类型:String 默认值: "application/x-www-form-urlencoded"。发送 信息至服务器时内容编码类型
success:function(data){
if(data.success){
.........................
return true;
}else{
............................
return true;
}
}
}
})
 
注:
  1:ajax 前台用traditional:true,后台使用springmvc 时参数这样写,可得到数据
    @RequestParam("test") Integer[] test
  2:dataType:"json", 返回的是json 对象,若是没有定义dataType,success:function(date){ }date 是json字符串,不是json对象
  json字符串转json对象。var jsonObj = $.parseJSON(date);
 
 
 
 
 
 
 
 
原文地址:https://www.cnblogs.com/2016-cxp/p/8654718.html