Jump to content

[SOLVED] Ajax not responding ?


balkan7

Recommended Posts

i have created code for check username, but ajax nothing respond me :(

 

code is:

 

<script>
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
	// Firefox, Safari, Opera...
	req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
	// Internet Explorer 5+
	req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
	// There is an error creating the object,
	// just as an old browser is being used.
	alert('Problem creating the XMLHttpRequest object');
}
return req;

}
var http = createRequestObject();
function useHttpResponseusername() {
  if (http.readyState == 4) {
var textOut = http.responseText;
var update = new Array();

document.getElementById('usercheck').innerHTML = textOut;
if(textOut.indexOf('|' != -1)) {
            update = textOut.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
  }
}
function checkusername(username) {
http.open('get', 'register.php?check=true&checkusername='+username+'&rand='+Math.random(), true);
http.onreadystatechange = useHttpResponseusername;
http.send(null);
}
</script>

 

php code:

<?php if(isset($_GET['check'])) {
echo "<style type='text/css'>
.quoteerror {
	color : #FFFFFF;
	background-color : #FF0000;
	border : 1px solid #C11B17;
}
</style>";
if(isset($_GET['checkusername'])) {
	$username = stripinput(trim(eregi_replace(" +", " ", $_GET['checkusername'])));
	if (!preg_match("/^[-0-9A-Z_@\s]+$/i", $username)) echo "<div class='quoteerror'><center>".$locale['403']."</center></div>";
	$result = dbquery("SELECT * FROM ".DB_USERS." WHERE user_name='$username'");
	if (dbrows($result) != 0) {
		$ajax_responde = "checkusername|<img src='images/icon_ajax_false.gif' border='0'> <span style='color: #FF0000;'>This username has already been taken</span>";
	} else {
		$ajax_responde = "checkusername|<img src='images/icon_ajax_true.gif' border='0'> <span style='color: #008000;'>This username is still available.</span>";
	}
	die();
}
}
?>

 

and

<input type='text' name='username' maxlength='30' class='textbox' style='width:200px;' onChange='checkusername(this.value)' /><div id='usercheck'></div>

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.