I'm trying to get php to send a response to the informational javaScript file, in which javaScript places a request for php in ajax, and php sends amount of information in random amount, php pulls from the database all records and will answer the ajax with this information, and finally javaScript will mount the html, I at first thought of mounting the html in php, but I saw that this is not a good option.
NOTE: There will be two PHP files that will generate the database and another that will receive the html through the ajax response.
My codes are just below.
javascrip
$.ajax({
url : "file.php",
type : "POST",
data : { alpha : null},
success : function(){console.log("work")},
error : function(){console.log("error")}
});
PHP
$q = "SELECT * FROM 'table'";
$r = $conn->query($q);
while ($row = $r->fetch_assoc()) {
}
echo json_encode($var); //Var || array || objeto
My question, how do I send this information back to javaScript?