Jump to content

What's wrong with this simple ajax function?


GuitarGod

Recommended Posts

Hi,

 

I don't know what's wrong with this ajax function, but it just won't work, if anyone could help, I'd be very grateful :D

 

function ajaxFunction( items )
{
	  var ajaxRequest;  

	  item_list = new Array;

	  for ( i = 0; i < items.length; i++ )
	  {
		    item_list[i] = items[i];
	  }

	  try
	  {
		  // Opera 8.0+, Firefox, Safari

		  ajaxRequest = new XMLHttpRequest();
	  } 
	  catch (e)
	  {
	        	  // Internet Explorer Browsers

		  try
		  {
			  ajaxRequest = new ActiveXObject( 'Msxml2.XMLHTTP' );
		  } 
		  catch (e) 
		  {
			  try
			  {
				  ajaxRequest = new ActiveXObject( 'Microsoft.XMLHTTP' );
			  } 
			  catch (e)
			  {
				  // Something went wrong

				  alert( 'Your browser not support ajax!' );
				  return false;
			  }
		  }
	  }

	ajaxRequest.onreadystatechange = function()
	{
		if ( ajaxRequest.readyState == 4 )
		{
			document.getElementById( 'username_available' ).style.display = '';
			document.getElementById( 'text' ).innerHTML = ajaxRequest.responseText;
		}
	}

	if ( !username )
	{
		alert( '<?= $lang->No_username_given; ?>' );
	}
	else
	{
		ajaxRequest.open( 'GET', './register.php?checkname=' + item_list[0] + '' );
		ajaxRequest.send( null ); 
	}
}

 

I'm terribly sorry for the format of the script, I realise that it's very hard to read. My HTML is

 

<input type="button" onclick="ajaxFunction( new Array( 'username' ) );">

 

Any ideas? Thanks  ;D

Hi,

 

I don't know what's wrong with this ajax function, but it just won't work, if anyone could help, I'd be very grateful :D

 

function ajaxFunction( items )
{
	  var ajaxRequest;  

	  item_list = new Array;

	  for ( i = 0; i < items.length; i++ )
	  {
		    item_list[i] = items[i];
	  }

	  try
	  {
		  // Opera 8.0+, Firefox, Safari

		  ajaxRequest = new XMLHttpRequest();
	  } 
	  catch (e)
	  {
	        	  // Internet Explorer Browsers

		  try
		  {
			  ajaxRequest = new ActiveXObject( 'Msxml2.XMLHTTP' );
		  } 
		  catch (e) 
		  {
			  try
			  {
				  ajaxRequest = new ActiveXObject( 'Microsoft.XMLHTTP' );
			  } 
			  catch (e)
			  {
				  // Something went wrong

				  alert( 'Your browser not support ajax!' );
				  return false;
			  }
		  }
	  }

	ajaxRequest.onreadystatechange = function()
	{
		if ( ajaxRequest.readyState == 4 )
		{
			document.getElementById( 'username_available' ).style.display = '';
			document.getElementById( 'text' ).innerHTML = ajaxRequest.responseText;
		}
	}

	if ( !username )
	{
		alert( '<?= $lang->No_username_given; ?>' );
	}
	else
	{
		ajaxRequest.open( 'GET', './register.php?checkname=' + item_list[0] + '' );
		ajaxRequest.send( null ); 
	}
}

 

I'm terribly sorry for the format of the script, I realise that it's very hard to read. My HTML is

 

<input type="button" onclick="ajaxFunction( new Array( 'username' ) );">

 

Any ideas? Thanks  ;D

 

The error is that username is not defined at,

 

if ( !username )

 

that part doesn't make any sense.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.