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 Link to comment https://forums.phpfreaks.com/topic/160632-whats-wrong-with-this-simple-ajax-function/ 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. Link to comment https://forums.phpfreaks.com/topic/160632-whats-wrong-with-this-simple-ajax-function/#findComment-847713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.