Bikkebakke Posted February 10, 2010 Share Posted February 10, 2010 Hi, I'm totally new to Ajax and I was wondering if this is somewhat correct or am I totally lost here. I got a button that should run a php script when clicked and heres the code: <input type='button' value='Heal' onClick="ajaxFunction();" name='heal' /> <br> <script language="javascript" type="text/javascript"> <!-- function ajaxFunction(){ ajaxRequest.open("GET", "heal.php", true); ajaxRequest.send(null); } //--> </script> And inside the heal.php is the code I want to be ran. Let me know if I should post more information or something, posted this in a little hurry. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/191611-is-this-written-right-ajax-button/ Share on other sites More sharing options...
Bikkebakke Posted February 10, 2010 Author Share Posted February 10, 2010 Oh I was so lost. I figured it out tho', the scripts so long I won't even bother copypasting it. Either way, this simple task was way more complex than I thought. Quote Link to comment https://forums.phpfreaks.com/topic/191611-is-this-written-right-ajax-button/#findComment-1010173 Share on other sites More sharing options...
Ang3l0fDeath Posted February 12, 2010 Share Posted February 12, 2010 Im going to say that looks pretty simple and correct. However you forgot to put the function ajaxFunction(){ ajaxRequest.onreadystatechange=function(){ if (ajaxRequest.readyState==4){ if (ajaxRequest.status==200){ var xml_response = ajaxRequest.responseXML; // how you output the responce is up to you Im guessing its in a DIV or TABLE where you want to output data. }}} ajaxRequest.open("GET", "heal.php", true); ajaxRequest.send(null);} Also you should look into PHP includes and$_GET If you managing multi files it might be useful. Also ajaxRequest.open("GET", "xml_output.php?page=heal", true); Thats just food for thought. Quote Link to comment https://forums.phpfreaks.com/topic/191611-is-this-written-right-ajax-button/#findComment-1011416 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.