zoukankan      html  css  js  c++  java
  • 2016年3月17日学习笔记----AJAX(网络协议)

    function btnClick() {
          var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//创建XMLHTTP对象,相当于WebClient
    if(!xmlhttp){
    alert("创建xmlhttp对象异常!");
    return false;
    }
    xmlhttp.open("POST","GetDatel.ashx?id="+encodeURI("中国")+"&ts"+new Date(),false);// 准备向服务器的 GetDate1.ashx发出POST请求。
    //XMLHTTP默认的(也推荐)不是同步请求的,也就是open方法不像WebClient的DownLoadString那样把服务器的数据拿到才返回,是异步的,因此需要监听onreadystatechange事件。
    xmlhttp.onreadystatechange = function() {
     if (xmlhttp.readyState == 4) {
        if(xmlhttp.status == 200){//如果状态码为200则是成功
            document.getElementById("TExt1").value =xmlhttp.responseText;//responseText属性为服务器返回的文本
    else {
    alert("AJAX服务器返回错误!");  
        }
      }
    }
    xmlhttp.send()://这时才开始发送请求
    }

     含有中文要使用encodeURI进行编译

    汇率计算代码:

  • 相关阅读:
    leetcode Lowest Common Ancestor of a Binary Tree
    leetcode 141、Linked list cycle
    leetcode 136、Single Number
    tensorflow使用
    c++ priority_queue
    python语法
    CSS基础之选择器
    并发编程的一些理解
    封装的绑定与多态
    继承与派生
  • 原文地址:https://www.cnblogs.com/quwujin/p/5286608.html
Copyright © 2011-2022 走看看