zoukankan      html  css  js  c++  java
  • Ajax之xmlHttpRequest

    var doc;
    window.onload 
    = function()
    {
        
    if(window.ActiveXObject)
        
    {
            doc 
    = new ActiveXObject("Microsoft.XMLHttp");
        }

        
    else if(window.XMLHttpRequest)
        
    {
            doc 
    = new XMLHttpRequest();
        }

    }


    function test()
    {
        doc.open(
    "Get","/Ajax/test.aspx",false);
        doc.onreadystatechange 
    = function()
        
    {
            
    if(doc.readystate == 4)
            
    {
                
    if(doc.status == 200)
                
    {
                    document.getElementById(
    "ddd").innerHTML = doc.responseText;
                }

                
    else
                
    {
                    document.getElementById(
    "ddd").innerTHML = "服务器返回状态:"+doc.statusText;
                }

            }

            
    else
            
    {
                document.getElementById(
    "ddd").innerHTML = "请等待.";
            }

        }

        doc.send(
    null);
    }

    aspx文件
    protected void Page_Load(object sender, EventArgs e)
    {
         Response.Write(
    "输出内容!");
    }

    另:实现调用一个aspx文件多个方法:

    调用时:
    doc.open(
    "Get","/Ajax/test.aspx?id=1",false);
    加个参数

    aspx文件代码:

    protected void Page_Load(object sender, EventArgs e)
    {
        
    string id = Request["id"];
        
    if(id==1)
           Response.Write(
    "结果1");
        
    else if(id==2)
           Response.Write(
    "结果2");
    }

    不过很遗憾,我所知道的基于xmlhttprequest的ajax不能支持firefox,找了很多资料也是,但可以借助ajaxPro,更好的办法是用jQuery库,它也是基于httprequest的,但还不知道它是怎么实现的。

  • 相关阅读:
    CSS画出三角形(利用Border)
    Javascript中style,currentStyle和getComputedStyle的区别以及获取css操作方法
    用canvas实现验证码的绘制
    tinymce富文本编辑器升级问题
    同步和异步
    this
    发送短信——案例
    SpringMvc框架【多测师】
    通过百度文字识别的API来实现把图片内容写入到txt文件当中【多测师】
    史上最全软件测试工程师常见的面试题总结(七)【多测师】
  • 原文地址:https://www.cnblogs.com/di305449473/p/1233777.html
Copyright © 2011-2022 走看看