新手AJAX
在这里,我想再次查询或select *from
在我的数据库上点击按钮并更改textarea内容?如何使用AJAX
执行此操作。
这是我的代码。
<textarea id="CKUPDATEALL">
<?php
$result = mysqli_query($con,"SELECT *FROM home WHERE ANNOUNCE_TYPE='WELCOMENOTE' ORDER BY ANNOUNCE_NUMBER DESC limit 0,1");
while($row = mysqli_fetch_array($result))
{
echo $row['ANNOUNCEMENTS'];
}
?>
</textarea>
答案 0 :(得分:1)
不,你可以设置你的php文件来检查Ajax调用中传递的不同变量。在Ajax响应中成功查找php文件中定义的不同变量。因此,您可以调用Ajax.php来获取10个不同的Ajax调用和响应。只需要正确设置它。
$(document).ready(function(){
$("#my_button").on('cick',function(){
Var name = $('#thisinputid').val();
$.ajax({
url: "getval.php",
type: "POST",
data : { fullname : name },
success: function(data) {
$("#CKUPDATEALL").val(data);
}
});
});
然后在php文件中检查$ _post ['fullname']。
答案 1 :(得分:0)
尝试 $.ajax() ,
$(function(){
$.ajax({
url:'get_announcement.php',
type:'POST',
data:{type:'announcement'},
success:funtion(d){
$('#CKUPDATEALL').val(d);
}
});
});
<强> get_announcement.php 强>
<?php
// type is announcement
if(isset($_POST['type']) and $_POST['type']=='announcement'){
$result=mysqli_query($con,"SELECT * FROM home WHERE
ANNOUNCE_TYPE='WELCOMENOTE' ORDER BY ANNOUNCE_NUMBER DESC limit 1");
while($row = mysqli_fetch_array($result)){
echo $row['ANNOUNCEMENTS'];
}
echo 'not found';
}
?>
答案 2 :(得分:0)
说这是你的按钮
<input type="button" id="my_button" value="Cick"/>
的Ajax
$(document).ready(function(){
$("#my_button").on('cick',function(){
$.ajax({
url: "getval.php",
type: "POST",
data : {'type':'textarea'},
success: function(data) {
$("#CKUPDATEALL").val(data);
}
});
});
在getval.php中
<?php
if(isset($_POST['type']) && trim($_POST['type']) == 'textarea'){
$result = mysqli_query($con,"SELECT * FROM home WHERE ANNOUNCE_TYPE='WELCOMENOTE' ORDER BY ANNOUNCE_NUMBER DESC limit 0,1");
while($row = mysqli_fetch_array($result)){
echo $row['ANNOUNCEMENTS'];
}
die();
}
?>