I am fiddling with ajax, the following doesn't work:
$(document).ready(function() {
$("button").click(function() {
$.post("\tests\test1.php", function(data) {
alert(data)
});
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<button>Click</button>
with test1.php
<?php
echo "Yes";
?>
The url is with respect to htdocs, so correct. Please point out the error.
You are using an incorrect url:
never use "\tests\test1.php"
Instead "/tests/test1.php" is the correct approach.
So your code becomes:
$.post( "/tests/test1.php", function( data ) {
alert(data);
});
I would also recommend you to use the full URL exaple:
http://example.com/tests/test1.php
instead of /tests/test1.php. (although not required but considered as a good approach.)