如何进行iframe式ajax调用

如何进行iframe式ajax调用

如何进行iframe式ajax调用,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

1.新建 a.html

 代码如下:


<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<title>iframe式ajax调用</title>
</head>
<body>
<form action='b.php' method='post' name='' id='' target='formTarget'>
<input type='text' name='username' id='' placeholder='' value='' />
<input type='submit' name='' value='提交' />
<span id='msg'></span>
</form>
<iframe src='' name='formTarget' id='formTarget' style='display:none'></iframe>
</body>
</html>


2.新建 b.php

 代码如下:


<?php
echo "
<script>
parent.document.getElementById('msg').innerHTML = 'iframe式ajax调用成功!';
alert('您输入的是:{$_POST['username']}');
window.setTimeout(function(){
parent.window.location.reload();
},3000);
</script>
";


3.访问: http://localhost/a.html

效果如图
如何进行iframe式ajax调用 

关于如何进行iframe式ajax调用问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。