immunity Posted June 19, 2007 Share Posted June 19, 2007 Hello in my display.htm i try to check if account / email exists (via Get Ajax) and it works fine then i try to post the values and pop up an alert box (registretion completed / there was a problem) althought (with putty) i see the mysql database was fast informed 1)I have to wait ~30sec until pop up box alert (http.requestText) (from the register.php file) 2) i have to press 2 times the sumbit bottun so second http request happends (1 time press only first http object that do Get Ajax works) <html> <head> <title>Customer Account Information</title> <script type="text/javascript"> var url = "check.php?account="; var permit = 0; function check() { if ( document.getElementById("account").value !="" && document.getElementById("email").value !="" ) { if ( emailCheck() ) { checkAccount(); } } else { alert("Ξ Ξ±ΟΞ±ΞΊΞ±Ξ»Ο ΟƒΟ…ΞΌΟ€Ξ»Ξ·ΟΟστε Ολα τα στοιχεία"); } if (permit ==1) { postForm(); } } function handleHttpResponse() { if (http.readyState == 4) { if(http.status==200) { var results=http.responseText; var test = results; if (test.match("2account1")== "2account1" ) { alert("Το ΟΞ½ΞΏΞΌΞ± λογαΟιασμου (account)υπάΟχει ήδη!\nΞ Ξ±ΟΞ±ΞΊΞ±Ξ»Ο Ξ΄ΞΉΞ±Ξ»Ξξτε κάποιο άλλο"); document.getElementById("account").value =""; document.getElementById("account").select(); } else if ( test.match("2email1") == "2email1" ) { alert("Το e-mail που εισάγατε υπάΟχει!\nΞ Ξ±ΟΞ±ΞΊΞ±Ξ»Ο Ξ΄ΞΉΞ±Ξ»Ξξτε κάποιο άλλο"); document.getElementById("email").value =""; document.getElementById("email").select(); } else if (test.match("2accountemail1") == "2accountemail1" ) { alert("To account ΞΊΞ±ΞΉ το e-mail που βάζετε υπάΟχουν!\nDeja-vu ?!?!?!?"); document.getElementById("email").value =""; document.getElementById("account").value =""; document.getElementById("account").select(); } else { http.abort(); permit=1; } } } } function emailCheck() { var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if(document.getElementById("email").value.length<1) { alert("dasdasdas e-mail"); return false; } else if(!regex.test(document.getElementById("email").value)) { alert("Το e-mail που εισάγεται δεν ΞµΞ―Ξ½Ξ±ΞΉ ΞΞ³ΞΊΟ…ΟΞΏ(Pro site)!\nΞ Ξ±ΟΞ±ΞΊΞ±Ξ»Ο ΞµΞΉΟƒΞ¬Ξ³ΞµΟ„Ξ±ΞΉ κάτι σαν [email protected]"); return false; } return true; } function checkAccount() { var sId = document.getElementById("account").value; var sEm = document.getElementById("email").value; http.open("GET", url + escape(sId)+"&email=" + escape(sEm), true); http.onreadystatechange = handleHttpResponse; http.send(null); } function postForm() { //var httppost = new getHTTPObject(); var url2 = "register2.php"; var params = "account=testisok&email=yeah"; http.open("POST", url2, true); //Send the proper header information along with the request http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.send(params); http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { alert(http.responseText); http.abort(); } } } function getHTTPObject() { var xmlhttp; if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject){ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); if (!xmlhttp){ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } } return xmlhttp; } var http = getHTTPObject(); // We create the HTTP Object </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head> <body> <p>Enter customer ID number to retrieve information:</p> <p>Account: <input type="text" id="account" value="" /></p> <p>E-mail :<input type="text" id="email" value="" /></p> <p><input type="button" value="Register" onClick="check()"/></p> <div id="divAccountInfo"></div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/56272-problem-handle-2-http-requests-its-take-about-30-sec-to-pop-up-alert-box/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.