I'm trying to pass two number and check if their product is true or false. I can see call made successfully in network tab and when i click that link, output is correct to. But i m stuck at retrieving that result. It doesn't show anything in data1.
function call(){
console.log(fun);
$.ajax({
url: "http://localhost/mt2/checkanswer.php",
dataType: "jsonp",
type: "POST",
//window.alert("what");
data: {
num1:2,
num2:2,
answer:5
},
success: function( data1 ) {
console.log(data1);
$( "#timeDiv" ).html( "<strong>" + data1 + "</strong><br>");
}
<?php
// get two numbers and the answer (their product) and return true or false if the answer is correct or not.
// using this as an api call, return json data
// calling <your host>/checkanswer.php?num1=4&num2=5&answer=20 will return true
// calling <your host>/checkanswer.php?num1=4&num2=5&answer=21 will return false
if(isset($_GET['num1']) && isset($_GET['num2']) && isset($_GET['answer']) && is_numeric($_GET['num1']) && is_numeric($_GET['num2']) && is_numeric($_GET['answer'])) {
$product = $_GET["num1"] * $_GET["num2"];
if ($product === intval($_GET['answer'])) {
$result = true;
} else {
$result = false;
}
header('Content-type: application/json');
echo json_encode($result);
}
?>
https://drive.google.com/open?id=1ocF344ZxG3HXJR0WQha1kOoVM9bCepnI "console"