Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    46
    Thanks
    9
    Thanked 2 Times in 2 Posts

    My file won't edit element properties

    Hello,

    So I have an ajax script that runs:

    Code:
    function test() {
    	var xmlhttp;
    	if (window.XMLHttpRequest)
    	  {
    	  // code for IE7+, Firefox, Chrome, Opera, Safari
    	  xmlhttp=new XMLHttpRequest();
    	  }
    	else
    	  {
    	  // code for IE6, IE5
    	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	  }
    	xmlhttp.onreadystatechange=function()
    	  {
    	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    		document.getElementById("eemail").innerHTML=xmlhttp.responseText;
    		}
    	  if (xmlhttp.readyState==3 && xmlhttp.status==200)
    		{
    		document.getElementById("mailtick").innerHTML="<img syle='vertical-align: middle;' src='images/icons/loading.gif' />";
    		}
    	}	
    	xmlhttp.open("POST","inc/username.php",true);
    	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    	xmlhttp.send('email=' + document.registration.email.value);
    }
    it runs great! but the problem is, when I try and set the 'mailtick' innerHTML to another picture from my username.php it doesn't work, any ideas how how to go about doing this securely?

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    readyStates 2 and 3 are
    not useful because they
    occur simultaneously with 4
    try this to see what i mean ...

    Code:
    <?PHP
    if(file_get_contents('php://input') != ""){
    	sleep(3);
    	echo $_REQUEST["email"];
    	
    }else{
    	echo <<<HTML
    <!doctype html>
    <html>
    <head>
    <script type="text/javascript">
    
    //document.getElementById("eemail").innerHTML=xmlhttp.responseText;
    //	document.getElementById("mailtick").innerHTML="";
    
    function sendit(){
    	var xmlhttp = new XMLHttpRequest;
    	xmlhttp.open("POST","index.php",true);	
    	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    	xmlhttp.onreadystatechange=function(){document.getElementById("mailtick").innerHTML += xmlhttp.readyState}
    	xmlhttp.send('email=' + document.registration.email.value)
    	
    }
    function test() {		
    	document.getElementById("mailtick").innerHTML="Waiting";
    	document.getElementById("eemail").innerHTML="";
    	setTimeout(sendit,1);	
    }
    </script>
    <body>
    <div id="mailtick"> </div>
    <div id="eemail"></div>
    <form name="registration">
    <input name="email">
    <button type="button" onclick="test()">TEST</button>
    </form>
    </body>
    </html>
    HTML;
    };
    ?>
    Last edited by DaveyErwin; 09-02-2012 at 08:02 PM.

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    46
    Thanks
    9
    Thanked 2 Times in 2 Posts
    Adding that in did teach me something but didn't answer my question,
    in the PHP file I'm echoing a <script></script> which sets a tick to a different Div, it won't let me do that, why?

    Regards

    Matthew

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    If you are saying
    xmlhttp.responseText will
    contain script tags ?,
    then
    the script will not be executed.

    it would be helpful to
    see what is returned
    from username.php

  • #5
    New Coder
    Join Date
    Aug 2011
    Posts
    46
    Thanks
    9
    Thanked 2 Times in 2 Posts
    It's okay, I found an alternative, the returned value is checked and the script is executed on the main page.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •