I have js function that triggered when I do something, and I want to call a php function. I know I need to use ajax to do so, but how exactly can I do it? I learn ajax, but I didn't find reference for it. Can you plz show me how its work. This is the basic of how I want it to work:
JS:call php function when JS triggered.
PHP:echo(or do) something.
EDIT: what I tring to get is infinite-scroll, that when I get to the bottom of the page it give me new php data. I follow this episode, and I want insdead of blue squares, to show data. this is the code of the episode. When the page to to the bottom it display blue square
<!DOCTYPE html>
<html>
<head>
<script>
function yHandler(){
// Watch video for line by line explanation of the code
// http://www.youtube.com/watch?v=eziREnZPml4
var wrap = document.getElementById('wrap');
var contentHeight = wrap.offsetHeight;
var yOffset = window.pageYOffset;
var y = yOffset + window.innerHeight;
if(y >= contentHeight){
// Ajax call to get more dynamic data goes here
wrap.innerHTML += '<div class="newData"></div>';
}
var status = document.getElementById('status');
status.innerHTML = contentHeight+" | "+y;
}
window.onscroll = yHandler;
</script>
<style>
div#status{position:fixed; font-size:24px;}
div#wrap{width:800px; margin:0px auto;}
div.newData{height:1000px; background:#09F; margin:10px 0px;}
</style>
</head>
<body>
<div id="status">0 | 0</div>
<div id="wrap"><img src="temp9.jpg"></div>
</body>
</html>