when to use ajax jquery to get data from php file, Does it need to echo in php file to return data? because I want to know if it has a case that not have to echo.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(function(){
$("#btn1").click(function(){
$.post("test2.php",
{
data1: $("#txt1").val(),
data2: $("#txt2").val()
},
function(resut){
$("#div1").html(resut);
}
);
});
});
</script>
</head>
<body>
<input type="text" id="txt1">
<input type="text" id="txt2">
<div id="div1"></div>
<input type="button" id="btn1" value="Load">
</body>
</html>
php file test2.php
<?php
echo "You input : <u>".$_POST["data1"]."</u> and <u>".$_POST["data2"]."</u>";
?>