您的位置:首页 > Web前端 > JavaScript

js 11行代码实现ajax

2010-09-18 12:37 260 查看
本代码在火狐,IE,GOOGLE浏览器中测试通过,请求aspx页默认(UTF-8)编码中文没有出现乱码,演示地址:http://www.haoy7.com 任何一个内容页
代码:
var ubType = (navigator.userAgent.indexOf("MSIE") > 0);
function AjaxObj(requestUrl, postData) {
var xmlhttp = null;
if (ubType)
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
else
xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", requestUrl, false);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(postData);
return xmlhttp.responseText;
}
注:代码是给需要的人看的,我也不是作家,请不要妄加评论谢谢。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: