Alright, so I have a related-posts.php script I wrote and I wish to insert it into posts only upon certain user action (scrolling). I also have a script file which is enqueued by wordpress and loads in footer - in there I've written ajax like so:
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("relatedPosts").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://localhost/wordpress/wp-content/themes/mytheme/functions/widgets/ajaxa.php",true);
xmlhttp.send();
AJAX loads the file, however the problem is: the php script seems to be 'unaware' of the page it loads in since
global $post;
print_r($post);
outputs 0 (zero)...
I understand there's a proper way of using ajax in wordpress however all the documentation I found relies heavily on Jquery (which I don't know nor wish to learn at the moment)
How can I make it work using javascript solely?