jquery一般通过$.ajax({});来使用ajax
$.ajax({
async: true, //默认为true使用异步
type: "POST", //请求的方式
url: "test.do", //请求的url
data: {id:12,name:'cl'}, //请求时携带的参数数据
dataType: "json", //接收数据的类型
success: function(_data){ //请求成功执行
alert( "Data Saved: " + _data );
}
});
其中data可以接收两种数据格式
- 字符串类型的数据格式为:name=chen&password=1234
- json类型的数据格式为:{name:‘chen’,password:‘1234’}
jquery对表单有一个serialize()方法可以非常完美的得到字符串类型格式为:name=chen&password=1234的数据