zoukankan      html  css  js  c++  java
  • django 笔记15 ajax系列

    参考 http://www.cnblogs.com/wupeiqi/articles/5703697.html
    # 原生操作
    # jQuery操作
    # 伪Ajax操作
    # XMLHttpReques
    伪ajax操作
    
    <iframe src='http://www.baidu.com'><iframe>  页面嵌套
    
    伪造一个ajax请求发往后台 页面不刷新
    iframe标签 和 form表单  target  iframe name
    
    <form action = "/ajax_json/" method = "POST" target = 'ifm1'>
        <iframe id = 'ifm1' name = 'ifm1' ></iframe>
        <input type = 'text' name = "username" />
        <input type = 'text' name = 'email' />
        <input type = 'submit' onclick="submitForm()" value = "提交"/>
    </form>
    <script>
        function submitForm(){
            $('#ifm1').load(function(){
                #在 iframe里找 返回的内容
                var text = $('#ifm1').contents().find('body').text();
                var obj = JSON.parse(text);
    
            })
        }
    <script>
    
    Ajax 原生的 jQuery 和iframe 三种
    时机:
        如果发送的是普通的数据 首先用jQuery 接着XMLHttpRequest,最后再考虑iframe
        如果发送的是不普通数据(文件)
    原生ajax操作
    function getXHR(){
        var xhr = null;
        if(XMLHttpRequest){
            xhr = new XMLHttpRequest();
        }else{
            xhr = new ActiveXobject('Microsoft.XMLHTTP');
        }
        return xhr;
    }
    
    function Ajax1(){
        var xhr = getXHR();
        xhr.open('POST', '/ajax_json/', true);
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4){
            //接收完毕后
            var obj = JSON.parse(xhr.responseText);
            console.log(obj)
            }
        };
        xhr.setRequestHeader('k1', 'v1');
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset-UTF-8');
        xhr.send('name=root; pwd=123')
    }


  • 相关阅读:
    非重复随机序列生成算法
    IE浏览器整页截屏程序
    地铁线路图的设计与实现
    拓扑排序算法的一个应用
    洛谷 P4450 双亲数
    洛谷 P2183 [国家集训队]礼物
    洛谷 P4159 [SCOI2009]迷路
    CF86D Powerful array
    Catalan数
    SP3266 KQUERY Kquery
  • 原文地址:https://www.cnblogs.com/Liang-jc/p/9265867.html
Copyright © 2011-2022 走看看