GuitarGod Posted June 2, 2009 Share Posted June 2, 2009 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 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 Quote Link to comment Share on other sites More sharing options...
rv20 Posted June 2, 2009 Share Posted June 2, 2009 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 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 The error is that username is not defined at, if ( !username ) that part doesn't make any sense. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.