ajax get post

來源:互聯網
上載者:User

標籤: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();
        }

分享:     
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.