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的,但还不知道它是怎么实现的。

  • 相关阅读:
    iOS 文件操作--归档和解档
    iOS中UITabBarController的使用
    Objective-C基础知识点总结,字符串操作,数组操作,字典操作
    Objective-C中协议和分类总结
    Objective-C文件操作之NSCoding协议之小练习
    浅谈Objective-C继承和多态
    Objective-C内存管理基础知识
    MySort(选做)的实现
    20175308 2018-2019-2 实验四 《Android开发基础》实验报告
    JAVA 第十一周学习总结
  • 原文地址:https://www.cnblogs.com/di305449473/p/1233777.html
Copyright © 2011-2022 走看看