zoukankan      html  css  js  c++  java
  • 交互ajax

    原生的js
    封装ajax
    1.创建ajax对象
    var oAjax=new XMLHttpRequest();//不兼容IE6
    var oAjax=new ActiveXobject('Microsoft.XMLHTTP');//iE6
    2.发送请求
    第一种
    oAjax.open("GET",url+"?"+data(),true)
    oAjax.send();//发送数据
    第二种
    oAjax.open("POST",url,true)
    oAjax.setRequestHeader("Content-type",'appLication/x=www=form-urlencoded');
    oAjax.send(data);//发送数据
    3.监听
    oAjax.onreadystatechange=function(){
        if(oAjax.readyState==4){
            if(oAjax.status>=200&&oAjax.status<300){
                succ&&succ(oAjax.responseText);
            }else{
                error&&error(oAjax.status());
            }
        }
    };
    注意:data()处理数据 主要是将数据变成json格式
    原生的跨域
    利用script标签或者利用代理

    jquery
    1.同一域中
    $.ajax({
        type:"get",//可以使get或者是post
        async:"true",//默认是true表示的是异步的
        url:"xxx.php",
        data:"xxxx",
        success:function(result){
            alert(result);
        },
    })
    2.跨域
    $.ajax({
        type:"get",
        url:"xxx",
        dataType:"jsonp",
        jsonp:"jsoncallback",
        success:function(data){
            alert(data);
        },
        error:function(){
            alert(fail);
        },
    })

  • 相关阅读:
    scgi_params
    ngin 模块及模板
    nginx常用模块
    HTML
    nginx部署网页小游戏
    nginx的server标签还有日志管理
    关于使用yum安装的nginx的主从配置文件的碎碎念
    判断所ping主机的操作系统
    CentOS 7修改主机名
    CentOS7 设置系统时间
  • 原文地址:https://www.cnblogs.com/GainLoss/p/5756553.html
Copyright © 2011-2022 走看看