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