It seems that you are using simple javascript to send the ajax request it is much easier with jQuery
. You do not have to check the browsers and many other things are simplified in jQuery.
Now for the flow part.
1.An event has to occur as to trigger the ajax request. It can be anything like blur,focus,click,load,mouseout,mousein its your choice.
code might look like this;
$($btn).click(function(){
insert your ajax request here
})
This says that the button has been clicked
2.call an ajax.
$.ajax({
url : "phpFile.php",
data : dataYouwantToSend,
success: function() {
code to do if the call is successful
}
})
3.process the data in php file
in phpFile.php
whatever you echo or print in the php file is going to show up as response from the file.
for example
if your php file only contain
echo "hello world";
response to your ajax request would be just hello world
.
4.process the response in ajax success function
success : function (response){ //the variable in the function can be anything
alert(response);
}
above example will alert hello world
the whole code would look like this. this is the html file.
<input type="text" id="clickMe" />
<script src="ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function(){
$("#clickMe").click(function(){
$.ajax({
url : "phpFile.php",
success : function(res) {
alert(res);
}
})
})
})
</script>
this is the php file
phpFile.php
echo "Hello world";