Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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