zoukankan      html  css  js  c++  java
  • day115-django-ajax

    详细:https://www.cnblogs.com/wupeiqi/articles/5703697.html
    
    ajax
        1.不刷新页面,向后台发送数据
        2.Ajax主要就是使用 【XmlHttpRequest】对象来完成请求的操作
        3.原生ajax:
                    GET请求:
                        var xhr = new XMLHttpRequest();
                        xhr.onreadystatechange = function(){
                            if(xhr.readyState == 4){
                                alert(xhr.responseText);
                            }
                        };
                        xhr.open('GET','/add2/?i1=12&i2=19');
                        xhr.send();
                    
                    
                    POST请求:
                        var xhr = new XMLHttpRequest();
                        xhr.onreadystatechange = function(){
                            if(xhr.readyState == 4){
                                alert(xhr.responseText);
                            }
                        };
                        xhr.open('POST','/add2/');
                        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                        xhr.send("i1=12&i2=19");
        4.伪Ajax,非XMLHttpRequest
                技术:
                    iframe标签,不刷新发送HTTP请求
                    <form>....</form>
                    iframe的name必须跟form的target一样才可以建立关联。
                
                示例:
                    <form id="f1" method="POST" action="/fake_ajax/" target="ifr">
                        <iframe id="ifr" name="ifr" style="display: none"></iframe>
                        <input type="text" name="user" />
                        <a onclick="submitForm();">提交</a>
                    </form>
    
                    <script>
                        function submitForm(){
                            document.getElementById('ifr').onload = loadIframe;
                            document.getElementById('f1').submit();
    
                        }
                        function loadIframe(){
                            var content = document.getElementById('ifr').contentWindow.document.body.innerText;
                            alert(content);
                        }
                    </script>
                        
                
  • 相关阅读:
    day18:json模块&time模块&zipfile模块
    Color Changing Sofa Gym
    Gym
    Gym
    Java的awt包的使用实例和Java的一些提示框
    分组背包 例题:hdu 1712 ACboy needs your help
    UVA1401 Remember the Word 字典树维护dp
    CodeForces833 B. The Bakery 线段树维护dp
    hdu4719 Oh My Holy FFF 线段树维护dp
    Little Difference Gym
  • 原文地址:https://www.cnblogs.com/python-daxiong/p/12862455.html
Copyright © 2011-2022 走看看