Chinaunix首页 | 论坛 | 博客
  • 博客访问: 558634
  • 博文数量: 34
  • 博客积分: 10171
  • 博客等级: 上将
  • 技术积分: 1365
  • 用 户 组: 普通用户
  • 注册时间: 2004-11-09 13:13
文章分类

全部博文(34)

文章存档

2011年(1)

2009年(20)

2008年(13)

我的朋友

分类:

2008-10-29 17:45:12

 

//使用

  var url=""+MobileNo.innerText;
  //alert(url) ;

  send_request("GET",url,null,"TEXT",processTextResponse);


//定义XMLHttpRequest对象实例

var http_request = false;
//定义可复用的http请求发送函数

function send_request(method,url,content,responseType,callback)
{//初始化、指定处理函数、发送请求的函数

        http_request = false;
        //开始初始化XMLHttpRequest对象

        if(window.XMLHttpRequest)
 { //Mozilla 浏览器

                http_request = new XMLHttpRequest();
                if (http_request.overrideMimeType)
  {//设置MiME类别

                        http_request.overrideMimeType("text/xml");
                }

        }
        else if (window.ActiveXObject)
 { // IE浏览器

                try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try {
                                http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                }
        }

        if (!http_request)
 { // 异常,创建对象实例失败

                window.alert("不能创建XMLHttpRequest对象实例.");
                return false;
        }
        if(responseType.toLowerCase()=="text")
 {
                //http_request.onreadystatechange = processTextResponse;

                http_request.onreadystatechange = callback;
        }
        else if(responseType.toLowerCase()=="xml")
 {
                //http_request.onreadystatechange = processXMLResponse;

                http_request.onreadystatechange = callback;
                window.alert("响应类别参数错误。");
                return false;
        }
        // 确定发送请求的方式和URL以及是否异步执行下段代码

        if(method.toLowerCase()=="get")
 {
                http_request.open(method, url, true);
        }

        else if(method.toLowerCase()=="post")
 {
                http_request.open(method, url, true);
                http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                http_request.setRequestHeader("Accept-Language","zh-cn");
        }
        else
 {
                window.alert("http请求类别参数错误。");
                return false;
        }
        http_request.send(content);
}
// 处理返回文本格式信息的函数

function processTextResponse()
{
        var element = document.getElementById("main");
        if (http_request.readyState == 4)
 {
                if (http_request.status == 200)
  {
                        //alert(http_request.responseText);

                        var p = http_request.responseText;
                        var errtd = document.getElementById("errtd");
                        errtd.innerHTML ="";
                        errtd.style.display = "";
                        var returnstr = p.split("|");
                        errtd.innerHTML = returnstr[1];
                        //errtd.innerHTML = p;

                        //if(p=="true"){

                        // //alert(p);

                        // var errtd = document.getElementById("errtd");

                        // errtd.innerHTML ="";

                        // errtd.style.display = "";

                        // errtd.innerHTML = "已成功提交了您的订购,稍后您的手机会收到短信,请回复“好”完成订购";

                        //}else{

                        // //alert(p);

                        // var errtd = document.getElementById("errtd");

                        // errtd.innerHTML ="";

                        // errtd.style.display = "";

                        // errtd.innerHTML = "您所在的地区没有上线";

                        //}


                } else
  {
                        alert("您所请求的页面有异常。");
 
                }
        }
        else
        {
                //timervar p = document.getElementById("progress");

                //p.innerText = "完成";

        }
}

阅读(7770) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~