Jump to content

Is this written right? Ajax button


Bikkebakke

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/191611-is-this-written-right-ajax-button/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.