码迷,mamicode.com
首页 > 其他好文 > 详细

ajax get post

时间:2014-07-18 10:09:23      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   width   

AJAX,get,post传参,readyState一直为0的原因

 (2012-11-18 16:33:12)
标签: 

it

 

原因

 

控件

 

编码

 

浏览器

分类: AJAX

        var xmlhttp;
        var htmltext;
        //通过浏览器的兼容性,获取"XMLHTTP"控件
        function getXMLRequster() {
            try {
                if (window.ActiveXObject) {
                    for (var i = 5; i > -1; i--) {
                        try {
                            if (i == 2)
                                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                            else
                                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP." + i + ".0");
                            break;
                        }
                        catch (e) {
                            xmlhttp = false;
                        }
                    }
                }
                else if (window.XMLHttpRequest) {
                    xmlhttp = new XMLHttpRequest();
                }
            }
            catch (e) {
                xmlhttp = false;
            }
        };
        //通过浏览器的兼容性,获取"XMLHTTP"控件
        //发送给后台
        function databand(indexnum) {
            getXMLRequster();

//问题所在


            xmlhttp.onreadystatechange = xmlhttp_onreadystatechange;

 

 

//(xmlhttp.onreadystatechange = xmlhttp_onreadystatechange();这样写的话

//xmlhttp.onreadystatechange为将xmlhttp_onreadystatechange的返回值赋给

//xmlhttp.onreadystatechange;而xmlhttp.onreadystatechange为当状态改变时调

//用函数xmlhttp_onreadystatechange所以应该这样写

//xmlhttp.onreadystatechange=xmlhttp_onreadystatechange;如果有参数的话这样//写:

//xmlhttp.onreadystatechange = functiong (){xmlhttp_onreadystatechange//(a,b);};)


            xmlhttp.open("GET", "Left.aspx?id=" + escape(indexnum), true); //get方法的escape编码
            xmlhttp.send(null); //get方法的

 

            xmlhttp.open("POST", "Left.aspx", true);//post方法
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //post方法,post必备的一句话
            xmlhttp.send("id=" + indexnum); //post方法


        }
        //发送给后台
        //判断回送
        function xmlhttp_onreadystatechange() {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    htmltext = xmlhttp.responseText;
                }
                else {
                }
            }
            else {
            }
        }
        //判断回送

//后台

//POST方法用Request.Form["id"]

        if (Request.Form["id"] != null)
        {
            string indexnum = Server.UrlDecode(Request.Form["id"]);
            if(indexnum == "1")
            Response.Write("<p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>1</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>1</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>dasfads</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>1</a></p>");
            else if(indexnum == "2")
                Response.Write("<p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>2</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>2</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>dasfads</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>2</a></p>");
            Response.End();
        }

//GET方法用 Request.QueryString["id"]

if (Request.QueryString["id"] != null)
        {
            string indexnum = Server.UrlDecode(Request.QueryString["id"]);
            if(indexnum == "1")
            Response.Write("<p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>1</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>1</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>dasfads</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>1</a></p>");
            else if(indexnum == "2")
                Response.Write("<p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>2</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>2</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>dasfads</a></p><p><img src=‘AdminImg/list_style.gif‘/><a href=‘#‘>2</a></p>");
            Response.End();
        }

ajax get post,布布扣,bubuko.com

ajax get post

标签:style   blog   http   color   os   width   

原文地址:http://www.cnblogs.com/lh123/p/3852455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!