zoukankan      html  css  js  c++  java
  • ajax

    本身是不能跨域的

    只能在服务器环境下才能运行

    from表单是要刷新本页面的,ajax就是可以让它不刷新页面来发送获取数据


    第一步:

      var x = new XMLHttpRequest()
    第二步:
      x.open()
      三个参数 :方式 路径 是否异步

    第三步:请求发送
      xhr.send();

    第四步:监听状态
      xhr.onreadystatechange = function(){
      if ( xhr.readyState === 4 ){
        alert( xhr.responseText );
        }
      };
    onreadystatechange 当状态码发生改变的时候触发
    readyState 状态码:
      0 请求还没建立 <open执行之前>
      1 请求已经建立,但是还没有发送 <open执行之后,send执行之前>
      2 请求已经发送 <send执行之后>
      3 请求处理部分完成,部分数据可用
      4 请求处理完全完成,所有数据可用(或者出现错误)
      responseText 返回的数据

    from表单中post和get的区别

    post不会在url显示,改成在请求头里面

    ajax中的区别

    get:
      a.open("get","get.php?user=wo&password=123",true)

    post;
      a.open("post","post.php",true;)
      a.setRequestHeader('content-type' , 'application/x-www-form-urlencoded');
      a.send("user=wo&password=123")

    a.status >= 200 && a.status < 300 代表没有出错

    处理字符串

    先将字符串转为json数组
    JSON.parse() ie9以上

    json转字符串:
    JSON.stringify()


  • 相关阅读:
    HDOJ 1241 Oil Deposits【最大连通块 dfs】
    POJ 3984 迷宫问题【迷宫最短路径 bfs】
    封装
    继承的另一种使用方式。。。
    类的绑定方法与继承
    XML模块与类的定义
    常用模块三
    python day19
    常用模块与项目目录规范
    python day17
  • 原文地址:https://www.cnblogs.com/wusan/p/7685991.html
Copyright © 2011-2022 走看看