$.ajax({
url: 'example.php',
type: 'POST',
data: {var: 12345},
success: function(data) {
console.log("success");
}
});
Your AJAX request expect a response (you assigned it to data
variable).
You should elaborate more the value returned by your PHP script, like console.log(data)
to see what it is returning.
Your PHP file can't write it directly to your html file, because it is a server-side operation and your page is already loaded. I think you should add some request-type logic in you PHP too if you want to have HTML file rendering and Javascript AJAX requests both in the same file.
A solution could be to catch the AJAX[POST] request in PHP code and return some HTML or String values to attach in HTML like $(body).append(data);
Here you can learn more: https://www.w3schools.com/php/php_ajax_php.asp