/**
* Ajax操作函数
*
* @param url -- 服务器端页面地址
* @param param -- 参数,类似 'user=123&id=100'
* @param method -- 请求服务器端的方法,Get和Post两种,默认是GET
* @param response -- 是否获取服务器端返回的结果,默认是true
*/
function ajax( url, param, method, response ){
//set default value
param = typeof(param)=='undefined' ? '' : param;
method = typeof(method)=='undefined' ? 'GET' : method;
response = typeof(response)=='undefined' ? true : response;
//get ajax object
var ajax = null;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = null;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined'){
ajax = new XMLHttpRequest();
}
if (!ajax){
alert("Get ajax object failed");
return false;
}
//send http request
var res = '';
if (method != 'GET'){
method = 'POST';
}
if (method == 'GET'){
ajax.open('GET', url + param, true);
ajax.onreadystatechange = function(){
if (ajax.readyState==4 && ajax.status==200){
res = ajax.responseText;
}
}
ajax.send(null);
}
if (method == "POST"){
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(param);
ajax.onreadystatechange = function() {
if (ajax.readyState==4 && ajax.status==200) {
res = ajax.responseText;
}
}
}
if (response){
return res;
}
return null;
}
* Ajax操作函数
*
* @param url -- 服务器端页面地址
* @param param -- 参数,类似 'user=123&id=100'
* @param method -- 请求服务器端的方法,Get和Post两种,默认是GET
* @param response -- 是否获取服务器端返回的结果,默认是true
*/
function ajax( url, param, method, response ){
//set default value
param = typeof(param)=='undefined' ? '' : param;
method = typeof(method)=='undefined' ? 'GET' : method;
response = typeof(response)=='undefined' ? true : response;
//get ajax object
var ajax = null;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = null;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined'){
ajax = new XMLHttpRequest();
}
if (!ajax){
alert("Get ajax object failed");
return false;
}
//send http request
var res = '';
if (method != 'GET'){
method = 'POST';
}
if (method == 'GET'){
ajax.open('GET', url + param, true);
ajax.onreadystatechange = function(){
if (ajax.readyState==4 && ajax.status==200){
res = ajax.responseText;
}
}
ajax.send(null);
}
if (method == "POST"){
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(param);
ajax.onreadystatechange = function() {
if (ajax.readyState==4 && ajax.status==200) {
res = ajax.responseText;
}
}
}
if (response){
return res;
}
return null;
}