zoukankan      html  css  js  c++  java
  • ajax/post请求

     1 <script>
     2     window.addEventListener('load', function (ev) {
     3         var btn = document.getElementById('send');
     4         btn.addEventListener('click', function (ev1) {
     5 
     6             // 1. 获取用户输入的内容
     7             var account = document.getElementById('account').value;
     8             var pwd = document.getElementById('pwd').value;
     9 
    10             // 2. 创建网络请求对象
    11             var xhr = new XMLHttpRequest();
    12             xhr.open('post', 'http://localhost:3000/api/five', true);
    13             // 设置请求头
    14             xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    15 
    16             xhr.send('name=zs&age=19');
    17             xhr.addEventListener('readystatechange', function (ev2) {
    18                 if(xhr.readyState === 4 ){
    19                    if(xhr.status === 200){
    20                        console.log(xhr.responseText);
    21                    }else {
    22                        console.log('请求失败!');
    23                    }
    24                 }
    25             });
    26         });
    27     });
    28 </script>
  • 相关阅读:
    Python生成器表达式
    Python列表解析
    Python迭代器(Iterator)
    Python set 集合
    python eval 函数妙用
    Python字典 (dict)
    Python序列之元组 (tuple)
    Python序列之列表 (list)
    递归和反射
    常用标准库
  • 原文地址:https://www.cnblogs.com/zhangzhengyang/p/11223441.html
Copyright © 2011-2022 走看看