A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 明光照 中级黑马   /  2012-9-22 16:38  /  1716 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

var xmlHttp;
var backInfo;
function AjaxEncode() {
    var userName = document.getElementById("userName").value;
    xmlHttp = new XMLHttpRequest();
    xmlHttp.open("post", "AJAXServer", true);
    xmlHttp.onreadystatechange = callback;
    //使用post方式发送请求需要自己设置http的请求头
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//    xmlHttp.send("name=" + userName);
    xmlHttp.send("name=" + encodeURI(userName));    //解决代码的乱码encodeURL()
}
function callback() {
    //alert(xmlHttp.status);//显示返回http状态的代码。成功的代码为200

    if (xmlHttp.readyState == 4) {
        var backInfo = xmlHttp.responseText;
//        alert(xmlHttp.responseText);
        //获取Id为result的那个结点。以便对其进行操作。
        var Innert = document.getElementById("result");
        //写入服务器返回的值到result结点
        Innert.innerHTML = backInfo;

    }
}

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

1 个回复

倒序浏览
值得学习ing!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马