I have some information got it from database and I want to send it through php file by an API the question is how to send this information and how to fetch it in javascript
I have some information got it from database and I want to send it through php file by an API the question is how to send this information and how to fetch it in javascript
It's the other way around, you consume the data from database using an API from the Javascript using the AJAX.
Javascript
var request = $.ajax({
url: "getData.php",
type: "post",
data: serializeData,
});
// Callback handler that will be called on success
request.done(function (response, textStatus, jqXHR){
console.log(response);
});
// Callback handler that will be called on failure
request.fail(function (jqXHR, textStatus, errorThrown){
console.error("The following error occurred: " + textStatus, errorThrown);
});
PHP
<?php
// Insert DB connection statements here
// Use $_POST['data'] to get the variables from HTTP POST request
$sql = "select * from table where column_name = 'Example'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
// Return specific row values
}
?>