[英]how I can send send information from php file to javascript file using API
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我有一些从数据库中获得的信息,我想通过 API 通过 php 文件发送它问题是如何发送这些信息以及如何在 javascript 中获取它
It's the other way around, you consume the data from database using an API from the Javascript using the AJAX.相反,您使用 API 从 Javascript 使用 AJAX 使用数据库中的数据。
Javascript 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
<?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
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.