reg.html
reg.html 페이지에는 iframe 태그가 있는데, 이 태그는 iframe을 사용하여 사용자 이름이 사용 가능한지 확인하기 위해 PHP를 요청합니다.
<code><span><!DOCTYPE html></span><span><<span>html</span>></span><span><<span>head</span>></span><span><<span>meta</span><span>charset</span>=<span>"utf-8"</span>></span><span><<span>title</span>></span> iframe局部刷新<span></<span>title</span>></span><span></<span>head</span>></span><span><<span>body</span>></span><span><<span>form</span><span>method</span>=<span>"post"</span><span>action</span>=<span>""</span>></span> 用户名:<span><<span>input</span><span>type</span>=<span>"text"</span><span>id</span>=<span>"uname"</span><span>name</span>=<span>'username'</span> /></span><span><<span>span</span><span>id</span>=<span>"msg"</span><span>style</span>=<span>"color:red;"</span>></span><span></<span>span</span>></span><span></<span>form</span>></span><span><<span>iframe</span><span>border</span>=<span>'0'</span><span>width</span>=<span>'0'</span><span>height</span>=<span>'0'</span><span>id</span>=<span>'myiframe'</span> ></span><span></<span>iframe</span>></span><span><<span>script</span><span>type</span>=<span>"text/javascript"</span>></span><span><span>//当用户名输入框失去焦点时让iframe请求check_reg.php</span> document.getElementById(<span>'uname'</span>).onblur = <span><span>function</span><span>()</span>{</span><span>if</span>(<span>this</span>.value != <span>''</span>) { document.getElementById(<span>'myiframe'</span>).src = <span>'check_reg.php?username='</span>+ <span>this</span>.value; } } </span><span></<span>script</span>></span><span></<span>body</span>></span><span></<span>html</span>></span></code>
check_reg.php
<code><span><span><?php</span>header(<span>"content-type:text/html;charset=utf-8"</span>); <span>$username</span> = <span>$_GET</span>[<span>'username'</span>]; <span>if</span>(<span>$username</span> == <span>'admin'</span>) { <span>$msg</span> = <span>'对不起,用户名已被使用!'</span>; }<span>else</span> { <span>$msg</span> = <span>'恭喜!该用户名可以使用。'</span>; } <span>echo</span><span><<<STR <script> window.parent.document.getElementById('msg').innerHTML = "$msg"; </script> STR;</span><span>?></span></span></code>
위 내용은 iframe의 내용을 포함하여 iframe을 통한 PHP의 부분 새로고침에 대해 소개하고 있으며, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.