zoukankan      html  css  js  c++  java
  • Ajax使用

    (从W3CShcool复制过来的,方便个人记忆)

    概念:

    AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)。

    AJAX 不是新的编程语言,而是一种使用现有标准的新方法

    -------------------------------------------------------------------------------------------------

    XMLHttpRequest 是 AJAX 的基础。

    XmlHttpRequest 术语缩写为XHR,中文可以解释为可扩展超文本传输请求。 

    ----------------------------------------------------------------------------------------------

    onreadystatechange 事件

    当请求被发送到服务器时,我们需要执行一些基于响应的任务。

    每当 readyState 改变时,就会触发 onreadystatechange 事件。

    readyState 属性存有 XMLHttpRequest 的状态信息。

    XMLHttpRequest 对象的三个重要的属性:

    onreadystatechange:存储函数(或函数名),每当 readyState 属性改变时,就会调用该函数。

    readyState:存有 XMLHttpRequest 的状态。从 0 到 4 发生变化。0: 请求未初始化1: 服务器连接已建立2: 请求已接收3: 请求处理中4: 请求已完成,且响应已就绪

    例子

    function GetDataFromDMS() {
        var tempVin = $("#VinForQuery").val();
        var targetUrl = "/DMS/ProcessInvoke?Vin=" + tempVin;
        var xmlHttpRequest;
        if (window.XMLHttpRequest) {
            xmlHttpRequest = new XMLHttpRequest();
        }
        else {
            xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlHttpRequest.onreadystatechange = function () {
            if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
                document.getElementById("response").innerHTML = xmlHttpRequest.responseText;
            }
        }
        xmlHttpRequest.open("Get", targetUrl, true);
        xmlHttpRequest.send();
    }

  • 相关阅读:
    Hsl PLC
    .NET平台常用框架整理
    SSH全注解实例详解
    word2vec (CBOW、分层softmax、负采样)
    pandas dataframe 一行变多行 (query pv统计term pv)
    python 按二维数组的某行或列排序 (numpy lexsort)
    基于决策树的分类算法
    【linux】 mail/mutt 发送邮件
    【python】含中文字符串截断
    【python】 判断纯ascii串
  • 原文地址:https://www.cnblogs.com/fengxiaoling/p/9121795.html
Copyright © 2011-2022 走看看