views.py
def ajax1 (Request):
ret={' status ': ' True ', ' message ': ' Successful '}
Return HttpResponse (Json.dumps (ret))
<iframe id= "I1" name= "Ifra" ></iframe>
<form id= "I2" method= "Get" action= "ajax1.html" target= "Ifra"# (onload= "Loadifram (this);") >
#target等于ifram的name, to bind the From to Ifram, if the onload event is bound on the label, the parameter this is required, and the function is defined above, otherwise the binding cannot be found
<input type= "text" value= "1111111111" >
#以下两种提交方法效果相同
#<input type= "Submit" value= "Submission" >
<a onclick= "AjaxSubmit5 ()" > Submit </a>
</form>
<script src= "/static/js/jquery-3.3.1.js" ></script>
<script>
function Loadifram () {#起到回调函数的作用
#两种方法找到ifram接收的内容, the following onload binding method, this is the Ifram tag
# Console.log (This.contentWindow.document.body.innerHTML);
# Console.log ($ (' #i1 '). Contents (). Find (' body '). html ());
var content=this.contentwindow.document.body.innerhtml
var res=json.parse (content)
if (res.status) {
Alert (res.message)
}
}
function AjaxSubmit5 () {
document.getElementById (' I1 '). Onload=loadifram;#提交时为ifram绑定onload事件
document.getElementById (' I2 '). Submit ();
}
Ajax---"Pseudo" Ajax