$.ajax()
$.ajax({
type:'GET', // 请求方法: GET/POST, 默认:GET
url:'ajax/ajax_checkAccountUserName', // 请求的地址
data:{param:'request'}, // 请求参数
dataType:'json', // 数据格式, json/xml/...
timeout:3000, // 请求的超时时间(单位:毫秒)。
cache:false, // 是否缓存上一次的数据,默认:true
async:true, // 同步/异步请求
beforeSend:function(){ // 发送请求前调用(一般不需要此函数)
alert('before send');
},
success:function(data){ // 请求成功后的回调函数
alert("$.ajax->" + data.account);
},
error: function(XMLHttpRequest, errMsg, errThrown) { //请求失败调用
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(errMsg);
}
});
$.get()
$.get(
'ajax/ajax_checkAccountUserName',
{param:'admin'}, // 请求参数(可以省略)
function(data) { // 请求成功后的回调函数(可以省略)
alert("$.get->" + data.account);
},
'json'
);
$.post()
$.post(
'ajax/ajax_checkAccountUserName',
{param:'admin2'}, // 请求参数(可以省略)
function(data) { // 请求成功后的回调函数(可以省略)
alert("$.post->" + data.account);
},
'json'
);
$.getJSON()
$.getJSON(
'ajax/ajax_checkAccountUserName',
{param:'admin'},
function(data) {
alert("$.getJSON->" + data.account);
}
);
补充:$.get() $.post() $.getJSON() 的同步/异步请求方法
$.ajaxSettings.async = false;