This is my JavaScript code:
$(FORM).on('submit', function (event) {
event.preventDefault();
$.get('server/example.php?number1=34&number2=46', function (response) {
console.log(response);
});
});
And this is my PHP file called example.php located in a directory called server:
<?php
$num1 = $_GET['number1'];
$num2 = $_GET['number2'];
$sum = $num1 + $num2;
echo($sum);
?>
When I make my get request, the response in Chrome DevTools (and console) prints the PHP code as the response instead of the value 80 (the sum of adding 34 and 46) when the console.log(response)
is called. I've tried the $.ajax()
method as well as explicitly instantiating and using the XMLHttpRequest
object. They all return/print the PHP code instead of 80. How do I get the value of $sum
?
I use BrowserSync when developing if that makes a difference (if it does, how can I do it differently).