Ajax与PHP进行交互操作
转载请注明来源:https://www.cnblogs.com/hookjc/
{
try{eval(resTxt);}
catch(e){alert(resTxt);}
}
//Ajax交互函数
function AjaxIn0(content)
{
var url=gAjaxUrl;
var callback_name='AjaxOut';
var async_request = false;
content='vars='+content;
if (window.XMLHttpRequest) // Mozilla/Safari
{
async_request = new XMLHttpRequest();
try{
async_request.overrideMimeType("text/xml");
}catch(e){;}
}
else if (window.ActiveXObject) // IE
{
async_request = new ActiveXObject("Microsoft.XMLHTTP");
}
async_request.open('POST',url, true);
async_request.setRequestHeader('Content-Type ','application/x-www-form-urlencoded');
async_request.onreadystatechange = function()
{
if (async_request.readyState == 4)
{
response_content = async_request.responseText;
eval(callback_name + '(response_content);');
async_request = null; //防止内存泄漏
}
}
async_request.send(content);
}
//Ajax交互函数
function AjaxIn(url,content,callback_name)
{
if(callback_name=='') callback_name='AjaxOut';
var async_request = false;
content='vars='+content;
if (window.XMLHttpRequest) // Mozilla/Safari
{
async_request = new XMLHttpRequest();
try{
async_request.overrideMimeType("text/xml");
}catch(e){;}
}
else if (window.ActiveXObject) // IE
{
async_request = new ActiveXObject("Microsoft.XMLHTTP");
}
async_request.open('POST',url, true);
async_request.setRequestHeader('Content-Type ','application/x-www-form-urlencoded');
async_request.onreadystatechange = function()
{
if (async_request.readyState == 4)
{
response_content = async_request.responseText;
eval(callback_name + '(response_content);');
async_request = null; //防止内存泄漏
}
}
async_request.send(content);
}