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)
http://www.spwg.ascribemeaning.com/lists/index.php 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 (http://www.spwg.ascribemeaning.com/lists/) 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 (http://www.spwg.ascribemeaning.com/lists/addevent.php)
Many Thanks
Ian
My code is as follows:-
<html>
<head>
<!— 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();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(“myDiv”).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,“http://www.spwg.ascribemeaning.com/lists/addevent.php?t=”,true);
xmlhttp.send();
}
//xmlhttp.open(“GET”,“ajax_info.txt”,true); // http://www.spwg.ascribemeaning.com/lists/addevent.php
// Sends request to Server “demo_get.asp?t=” - add a unique ID to the URL
function myFunction()
{
//loadXMLDoc(“ajax_info.txt”,function()
loadXMLDoc(“http://www.spwg.ascribemeaning.com/lists/addevent.php?t=”,function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(“myDiv”).innerHTML=xmlhttp.responseText;
}
});
}
</script>
</head>
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
Ian