GuitarGod Posted June 25, 2009 Share Posted June 25, 2009 Hi, I keep getting an error when I try to use this ajax script. So far I can't tell anything wrong with it. Any help? function ajaxFunction( item_list ) { var ajaxRequest; var items = ajaxFunction.arguments.length; var item_array = new Array(); for ( i = 0; i < items; i++ ) { item_array[i] = ajaxFunction.arguments[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( 'notes' ).innerHTML = ajaxRequest.responseText; } } note_param = 'note='+item_array[1]+''; ajaxRequest.open( 'POST', './control.php?ajax=listnotes', TRUE ); ajaxRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); ajaxRequest.setRequestHeader('Content-length', '1'); ajaxRequest.setRequestHeader('Connection', 'close'); ajaxRequest.send( note_param ); } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 25, 2009 Share Posted June 25, 2009 the only thing I had to change was 'TRUE' to 'true': <script> function ajaxFunction( item_list ) { var ajaxRequest; var items = ajaxFunction.arguments.length; var item_array = new Array(); for ( i = 0; i < items; i++ ) { item_array[i] = ajaxFunction.arguments[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( 'notes' ).innerHTML = ajaxRequest.responseText; } } note_param = 'note='+item_array[1]+''; ajaxRequest.open( 'POST', './control.php?ajax=listnotes', true ); ajaxRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); ajaxRequest.setRequestHeader('Content-length', '1'); ajaxRequest.setRequestHeader('Connection', 'close'); ajaxRequest.send( note_param ); } </script> <input type="button" value="TEST" onclick="ajaxFunction('first','my note')" /> <div id="notes">This is the starting text</div> <?php print_r($_POST); ?> if you use jQuery though, we can shorten this up a bit: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> function ajaxFunction( ) { $.post('control.php?ajax=listnotes',{note:ajaxFunction.arguments[1]},function(data){ $('#notes').html(data); }); } </script> <input type="button" value="TEST" onclick="ajaxFunction('first','my note')" /> <div id="notes">This is the starting text</div> Quote Link to comment Share on other sites More sharing options...
GuitarGod Posted June 25, 2009 Author Share Posted June 25, 2009 That worked perfectly Thank you very much! I can't believe such a small thing can make such a big difference. Thanks once again 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.