伪Ajax,非XMLHttpRequest

  • 伪Ajax,非XMLHttpRequest,iframe标签

# iframe标签,不刷新发送Http请求
# view.py
def autohome(request):
    if request.method == 'GET':
        return render(request,'autohome.html')

# autohome.html

<body>
<div>
    <input type="text" id="text1">
    <input type="button" value="提交" onclick="changeSrc()">
</div>
<iframe id="text2" style="width: 1000px;height: 2000px" src="http://www.autohome.com.cn"></iframe>

</body>
<script src="/static/jquery-3.2.1.js"></script>
<script>
    function changeSrc() {
        /*
        var cont = $('#text1').val();
        $('#text2').attr('src',cont);
        */
        var cont = document.getElementById('text1').value;
        document.getElementById('text2').src = cont
    }
</script>


# iframe + form 进行伪Ajax

# views.py
def fake_ajax(request):
    if request.method == 'GET':
        return render(request,'fake_ajax.html')
    else:
        print('post.ok')
        print(request.POST.get('user'))
        return HttpResponse('ok')

# fake_ajax.html

<body>
<input type="text">
<form id="f1" action="/fake_ajax/" target="ifr" method="post">
    <iframe id="ifr" name="ifr" style="display: none"></iframe>
    <input type="text" name="user" />
    <input type="submit" />
</form>
</body>

# 加上伪造的'回调函数'

# views.py
def fake_ajax(request):
    if request.method == 'GET':
        return render(request,'fake_ajax.html')
    else:
        print('post.ok')
        content = request.POST.get('user')
        return HttpResponse(content)


# fake_ajax.html   
<body>
<input type="text">
<form id="f1" action="/fake_ajax/" target="ifr" method="post">
    <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>
</body>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值