zoukankan      html  css  js  c++  java
  • 伪Ajax-iframe

    由于HTML标签的iframe标签具有局部加载内容的特性,所以可以使用其来伪造Ajax请求。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
    <input type="text" id='url'>
    <input type="button" value="发送iframe请求">
    <iframe id="ifm" src="http://www.baidu.com"></iframe>
    
    
    <form action="/xiaoqing/ajax_json/" method="post" target="ifm1">
        {% csrf_token %}
    
        <iframe id="ifm2" name="ifm1"></iframe>
        <input type="text" name="username">
        <input type="text" name="email">
        <input type="submit" onclick="submitForm();" value="Form提交" >
    
    </form>
    
    <script src="/static/jquery-1.12.4.js"></script>
    <script>
    
    
            $(function () {
    
                $(':button').click(
    
                    function () {
                        var url=$('#url').val();
                         $('#ifm').attr('src',url);
    
                    }
                )
    
    
            })
    
           function submitForm() {
    
               $('#ifm2').load(function(){
    
                var text= $('#ifm2').contents().find('body').text();  #这个地方要注意
                var obj= JSON.parse(text);
                  console.log(obj);
               })
    
           }
    
    
    
    
    </script>
    
    </body>
    </html>
    iframe.html
    import json
    def ajax_json(request):
    
        ret = {'status':True,'data':request.POST.get('username')}
    
    
        return HttpResponse(json.dumps(ret))
    
    def iframe(request):
        return render(request,'iframe.html')
    views.py
  • 相关阅读:
    忙活了半宿,写了个小玩意
    luogu P5171 Earthquake
    luogu P1850 换教室
    luogu P2507 [SCOI2008]配对 |动态规划
    luogu P3830 [SHOI2012]随机树
    luogu P3959 宝藏
    牛客竞赛-比赛
    牛客竞赛-Who killed Cock Robin
    luogu P3807 【模板】卢卡斯定理
    牛客竞赛 -被3整除的子序列
  • 原文地址:https://www.cnblogs.com/sunhao96/p/9024816.html
Copyright © 2011-2022 走看看