ajax get,post提交數據
//ajaxRead("http://page.aspx?aa=jj&bb=3434",post);
function ajaxRead(file,type){
var xmlObj = null;
if(window.XMLHttpRequest){
xmlObj = new XMLHttpRequest();
} else if(window.ActiveXObject){
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
} else {
return;
}
xmlObj.onreadystatechange = function(){
if(xmlObj.readyState == 4){
//回調函數
callback(xmlObj.responseText);
}
}
if(file.indexOf("?")>-1)
{
file+="&r="+Math.random();
}
else
{
file+="?r="+Math.random();
}
switch(type.toUpperCase())
{
case "GET":
xmlObj.open ('GET', file, true);
xmlObj.send (null);
break;
case "POST":
xmlObj.open("POST",file,true);
xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
var querystring=file.substr(file.indexOf("?")+1);
xmlObj.send(querystring);
break;
default:
break;
}
}
function callback(response)
{
//返回值的處理
alert(response);
}
function ajaxRead(file,type){
var xmlObj = null;
if(window.XMLHttpRequest){
xmlObj = new XMLHttpRequest();
} else if(window.ActiveXObject){
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
} else {
return;
}
xmlObj.onreadystatechange = function(){
if(xmlObj.readyState == 4){
//回調函數
callback(xmlObj.responseText);
}
}
if(file.indexOf("?")>-1)
{
file+="&r="+Math.random();
}
else
{
file+="?r="+Math.random();
}
switch(type.toUpperCase())
{
case "GET":
xmlObj.open ('GET', file, true);
xmlObj.send (null);
break;
case "POST":
xmlObj.open("POST",file,true);
xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
var querystring=file.substr(file.indexOf("?")+1);
xmlObj.send(querystring);
break;
default:
break;
}
}
function callback(response)
{
//返回值的處理
alert(response);
}