HTML Code:
<script type='text/javascript'>
function ajaxFunc() {
var data1; // populate however you want
var data2; // same here
var ajaxReq;
try {
// Opera 8.0+, Firefox, Safari
ajaxReq = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try {
ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
var queryString = "?id="+data1+"&id2="+data2;
ajaxReq.open("GET", 'ajaxscript.php' + queryString, true);
ajaxReq.onreadystatechange = function() {
if(ajaxReq.readyState == 4){
response = ajaxReq.responseText;
alert(response);
}
}
ajaxReq.send(null);
}
</script>
Invoke the ajaxFunc() however fits your needs. Populate the necessary data you will be passing. Then put the code below in your ajaxscript.php.
That's all you should need to understand how to get you started in Ajax.
PHP Code:
<?php
echo "Your first data is : ".$_GET['id']." and second is : ".$_GET['id2'];
?>
Bookmarks