作者TonyQ (骨头)
看板Ajax
标题Re: [问题] 有关登入
时间Tue Nov 27 13:37:18 2007
※ 引述《j87b0003 (10Ways-拥抱高雄)》之铭言:
: 不知道大家是怎麽做的?
: 因为是用thickbox开启一层的登入页面,如下:
: 呼叫loginFormSubmit()
: 程式码:
: function check(account,password){
: if(account == "" || password == "")return false;
: else{
: var str='account='+account+'&password='+password+'&login=true';
: if(xmlhttp) {
: xmlhttp.open("POST", "check.php", true);
: xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
: xmlhttp.onreadystatechange = function(){
: if (xmlhttp.readyState == 4 &&xmlhttp.status ==200){
: xmlResponse = xmlhttp.responseXML;
: xmlDocumentElement = xmlResponse.documentElement;
: message = xmlDocumentElement.firstChild.data;
: }
: }
: xmlhttp.send(str);
: }
: }
: }
: 回传的xml,如果登入成功是1,失败是0
: 而我的问题是
: 因为等回传完的时候,程式早就跑完了...
: 如何改进?
: 谢谢各位指教
作法 1. 把xmlhttp.open("POST", "check.php", true);
改成xmlhttp.open("POST", "check.php", false);
变成非同步 , 缺点是会有点卡卡的
作法 2. 在onreadystatechange把剩下的程式呼叫写进去
因为这东西是保证回传完才会跑到的。
--
▄▅▆▇███▇▆▅▄▃ ╰┼╯─╮ ╮
◥███████████◣ ╰┼╯=│=│
◥██████───────◣ *. ╯ ╯ ╯ の 物 语 .*
◥███████──────◣ ~ ◢◣ ◢◣
◥██████───────◤ ◥◤* 空白的世界.翼
*◥◤
◥██▁▂▃▄▅▆▇███▆▅▄▃▂▂
~telnet://tony1223.no-ip.info
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.132.59.247
1F:推 j87b0003:感谢XD" 11/27 23:15