Jump to content

problem handle 2 http requests( its take about 30 sec to pop up alert box:/ )


immunity

Recommended Posts

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Ξ Ξ±ΟΞ±ΞΊΞ±Ξ»Ο ΞµΞΉΟƒΞ¬Ξ³ΞµΟ„Ξ±ΞΉ κάτι σαν name@domainname.com");
			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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.