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);
        },
    })

  • 相关阅读:
    Java二维数组
    Java实现冒泡排序
    python类简记
    LaTeX:论文Instruction最后一段的章节引用
    在Adobe IIIustator中加入数学公式——配合MathType使用
    org.springframework.web.bind.annotation不存在
    xshell5 下载安装
    MultipartFile解析Excel
    开源项目环境搭建
    学习路线
  • 原文地址:https://www.cnblogs.com/GainLoss/p/5756553.html
Copyright © 2011-2022 走看看