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

Link to comment
Share on other sites

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.

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.