Javascript/AJAX help!

Hitman
Soldato
Joined
25 Feb 2004
Posts
2,837
Hi,

I've made a register form for my website using AJAX to send the data and display the result.

The register function (and extra bits):
Code:
function createRequestObject( ) {
	var req;

	if( window.XMLHttpRequest ){
		req = new XMLHttpRequest();
	} else if( window.ActiveXObject ) {
		req = new ActiveXObject( "Microsoft.XMLHTTP" );
	} else {
		alert( "There was a problem creating the XMLHttpRequest object" );
	}
	
	return req;
}

var http = createRequestObject( );

function sendRegisterPost( ) {
	var user = document.getElementById( "user" ).value;
	var email = document.getElementById( "email" ).value;
	var mothername = document.getElementById( "mothername" ).value;
	var pass1 = document.getElementById( "pass1" ).value;
	var pass2 = document.getElementById( "pass2" ).value;
	var ipb_acc = document.getElementById( "ipb_acc" ).value;
	var ipb_display = document.getElementById( "ipb_display" ).value;
	var ipb_pass = document.getElementById( "ipb_pass" ).value;
	var ipb_pass_control = document.getElementById( "ipb_pass_control" ).value;
	
	http.open( "POST", "do_register.php", true );
	http.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
	http.onreadystatechange = handlePost;
	http.send( "user="+ user +"&email="+ email +"&mothername="+ mothername +"&pass1="+ pass1 +"&pass2="+ pass2 +"&ipb_acc="+ ipb_acc +"&ipb_display="+ ipb_display +"&ipb_pass="+ ipb_pass +"&ipb_pass_control="+ ipb_pass_control );
}

The following is the handlePost function:
Code:
function handlePost( ) {
	if( http.readyState == 1 ) { 
		document.getElementById( "response" ).innerHTML = "<div id=\"loading\"><center><img src=\"loading.gif\"></center></div>";
	} else if( http.readyState == 4 && http.status == 200 ) {
		var response = http.responseText;
		if(response) {
			document.getElementById( "response" ).innerHTML = response;
		}

	}
}

Now the problem I have is that this works fine for some, but not for others. For me, the loading bar shows whilst it's doing its thing, then displays the output. For others, they hit "Register" and nothing shows or anything.

A person trying to register reported that once you click Register on Internet Explorer, "Error on Page!" message shows. However, FireFox and Internet Explorer work fine for me.

Is there something I've done wrong in the above which would cause this?

Would appreciate any help :)

Cheers
 
Last edited:
What version of IE do they have? IE 6 and IE7 handle AJX requests differently. Consider using something like mootools which wraps the browser functions in classes so you don't have to worry about that browser not compatible non sense
 
What version of IE do they have? IE 6 and IE7 handle AJX requests differently. Consider using something like mootools which wraps the browser functions in classes so you don't have to worry about that browser not compatible non sense

I actually have no idea - I should probably ask :p

I'll check "mootools" out - thanks for that :). Quick question: would I have to re-write all of my code for mootools?
 
Back
Top Bottom