即时通讯使用ajax和php在我的android应用程序来查询我的数据库。ajax发布到php并检索sql结果
我能够以检索所有的结果,但不知道如何给一个变量发送到我的PHP,这样我可以把它作为一个自定义查询和retrive的结果......是这样的:
$id = $_POST['id'];
$sql = "SELECT * FROM mobile_app WHERE nome LIKE '{%id%}'";
但不能让我的AJAX发布变量和retrive结果...
这是我的代码:
我的移动应用程序:
$.ajax({
url: "http://www.example.com/mobile_read.php", // path to remote script
dataType: "JSON", // data set to retrieve JSON
success: function (data) { // on success, do something...
// grabbing my JSON data and saving it
// to localStorage for future use.
localStorage.setItem('myData', JSON.stringify(data));
}
});
我的PHP:
$sql = "SELECT * FROM mobile_app";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$output[] = array (
"nome" => $row['nome'],
"status" => $row['status'],
"hentrada" => $row['hentrada'],
"evento" => $row['evento']
);
}
} else {
echo "0 results";
}
$conn->close();
echo json_encode($output);
Y你需要为你的ajax调用添加数据属性。我的假设是你需要发布身份证。 –