Calling a php file using a button

Very, very early learning days

I am displaying a number of buttons in a table.

“<button type=\“button\” onclick=\”\“>Add Event</button>” ;

How do I call a php file addevent.php (which will contain an update form) is where I am playing.

Use the onclick event to call a javascript function that makes an Ajax call to a server side php function.

Thanks for coming back.

I have worked through
AJAX Create an XMLHttpRequest Object
to try and understand how AJAX works.

I thought that I had my code right to satisfy the clicking of the ‘Add Event’ button ( but I have missed something along the way. Am I on the right track? Could you please tell me where I am going wrong.

(If index.php reads addevent.php then a big fat ‘GOTCHA!’ is supposed todisplay - see (

Many Thanks

My code is as follows:-

<!— Create XMLHttpRequest Oject using function in Head —>
<script type=“text/javascript”>
function addevent() // Changed from loadXMLDoc() to addevent()
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);

if (xmlhttp.readyState==4 && xmlhttp.status==200)
//“GET”,“ajax_info.txt”,true); //
// Sends request to Server “demo_get.asp?t=” - add a unique ID to the URL

function myFunction()
if (xmlhttp.readyState==4 && xmlhttp.status==200)


The best source for learning ajax seems to be the Bulletproof Ajax book, which also gives you free [url=“”]code and examples to learn from…

Thank you for that. I have ordered the book from Amazon and expect delivery early June.
Meanwhile it is a dark, miserable, cold, wet, unseasonal Bank Holiday Monday in the UK, ideal for programming. Please could someone help me out with my code.
Thanks Guys

My pumpkin will be here shortly as it’s nearing midnight, but you can check out the fully working sample code from the HTML—People part of Chapter 4, which is purposefully designed to be a fully [url=“”]working example of [url=“”]how to use Ajax to read HTML content and use it to update a section of the page.