您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 编程语言综合 >> 正文

iframe式ajax调用示例

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 想必大家对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