Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-02-2012, 05:23 PM   PM User | #1
GreenFanta
New Coder

 
Join Date: Aug 2011
Posts: 46
Thanks: 9
Thanked 2 Times in 2 Posts
GreenFanta is an unknown quantity at this point
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?
GreenFanta is offline   Reply With Quote
Old 09-02-2012, 06:58 PM   PM User | #2
DaveyErwin
Regular Coder

 
Join Date: Aug 2010
Posts: 810
Thanks: 12
Thanked 168 Times in 166 Posts
DaveyErwin is on a distinguished road
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..
DaveyErwin is offline   Reply With Quote
Old 09-02-2012, 11:26 PM   PM User | #3
GreenFanta
New Coder

 
Join Date: Aug 2011
Posts: 46
Thanks: 9
Thanked 2 Times in 2 Posts
GreenFanta is an unknown quantity at this point
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
GreenFanta is offline   Reply With Quote
Old 09-02-2012, 11:51 PM   PM User | #4
DaveyErwin
Regular Coder

 
Join Date: Aug 2010
Posts: 810
Thanks: 12
Thanked 168 Times in 166 Posts
DaveyErwin is on a distinguished road
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
DaveyErwin is offline   Reply With Quote
Old 09-03-2012, 12:11 AM   PM User | #5
GreenFanta
New Coder

 
Join Date: Aug 2011
Posts: 46
Thanks: 9
Thanked 2 Times in 2 Posts
GreenFanta is an unknown quantity at this point
It's okay, I found an alternative, the returned value is checked and the script is executed on the main page.
GreenFanta is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:51 AM.


Advertisement
Log in to turn off these ads.