发送无数据的ajax请求,PHP检查isset
我有下面这段代码,目前可以使用。我想要的是删除url并在同一页面上处理ajax请求。由于我没有发送任何数据,当我的ajax函数准备好向数据库发送请求时,如何让php检查 我使用jquery mousedown按住按钮,然后在1秒后用户收到删除提示。如果用户按住列表上的按钮5,则会删除mysql表中的第5行,按钮10会删除第10行等发送无数据的ajax请求,PHP检查isset,php,jquery,ajax,Php,Jquery,Ajax,我有下面这段代码,目前可以使用。我想要的是删除url并在同一页面上处理ajax请求。由于我没有发送任何数据,当我的ajax函数准备好向数据库发送请求时,如何让php检查 我使用jquery mousedown按住按钮,然后在1秒后用户收到删除提示。如果用户按住列表上的按钮5,则会删除mysql表中的第5行,按钮10会删除第10行等 $("#outter_div_5").mousedown('#button_5', function(e) { clearTimeout(this.d
$("#outter_div_5").mousedown('#button_5', function(e) {
clearTimeout(this.downTimer);
this.downTimer = setTimeout(function() {
var prompt_user = prompt('Enter "e" to Edit \nEnter "d" to Delete');
if (prompt_user== "d")
{
$.ajax({
url: './ajax/5/delete.php', // <-- I want to remove this line and process this ajax request on the same page
type:'POST',
data: {},
success:function(result){
$("outter_div_5").fadeOut(125);
},
complete:function(data){
$.ajax({
url:'reload_table.php',
method:'POST',
success:function(data){
// reload javascript variables and html table
$("#my_table").html(data);
}
});
}
});
}
}, 1000);
}).mouseup(function(e) {
clearTimeout(this.downTimer);
});
我需要创建一个PHPIsset,以便在同一页面上处理这个ajax请求。我该怎么做
<?php
if( isset($_POST['']) ){
$sql = "UPDATE my_table SET row = '' WHERE id = '5' ";
mysqli_query($conn,$sql);
}
?>
<script>
$("#outter_div_5").mousedown('#button_5', function(e) {
clearTimeout(this.downTimer);
this.downTimer = setTimeout(function() {
var prompt_user = prompt('Enter "e" to Edit \nEnter "d" to Delete');
if (prompt_user== "d")
{
$.ajax({
url: './ajax/5/delete.php', // <-- I want to remove this line and process this ajax request on the same page
type:'POST',
data: {},
success:function(result){
$("outter_div_5").fadeOut(125);
},
complete:function(data){
$.ajax({
url:'reload_table.php',
method:'POST',
success:function(data){
// reload javascript variables and html table
$("#my_table").html(data);
}
});
}
});
}
}, 1000);
}).mouseup(function(e) {
clearTimeout(this.downTimer);
});
</script>
HTTP(在您的例子中使用AJAX)请求的主要优点是,您不必重新加载页面或重定向用户以将信息传递给服务器。可以找到其他一些优势和更多信息。请注意,php代码是在运行任何javascript之前运行的
如果您不想使用HTTP请求,您有多种解决方案。这是我的:
您可以使用带有method=“POST”
()的表单,在提交前使用提示,而不是此类HTTP请求:
$(“删除按钮”)。单击(功能(事件){
event.preventDefault();
var prompt_user=prompt('输入“e”编辑\n输入“d”删除');
如果(提示用户==“d”){
控制台日志(“已提交”);
//$(“#我的表格”).submit();
}else if(提示用户==“e”){
控制台日志(“编辑”);
//添加用于编辑要编辑的内容的操作。
}否则{
控制台日志(“中止”);
}
})
我并非有意粗鲁,但我认为您不明白ajax请求的目的是什么。相反,您可以将表单
与method=“POST”
一起使用,该表单是通过javascript或类似的东西触发的。我还是个初学者,所以不需要冒犯。如果我在ajax请求中使用url,代码就可以工作。我只是想让它工作,这样我就可以在同一页上做请求。
<?php
if( isset($_POST['']) ){
$sql = "UPDATE my_table SET row = '' WHERE id = '5' ";
mysqli_query($conn,$sql);
}
?>
<script>
$("#outter_div_5").mousedown('#button_5', function(e) {
clearTimeout(this.downTimer);
this.downTimer = setTimeout(function() {
var prompt_user = prompt('Enter "e" to Edit \nEnter "d" to Delete');
if (prompt_user== "d")
{
$.ajax({
url: './ajax/5/delete.php', // <-- I want to remove this line and process this ajax request on the same page
type:'POST',
data: {},
success:function(result){
$("outter_div_5").fadeOut(125);
},
complete:function(data){
$.ajax({
url:'reload_table.php',
method:'POST',
success:function(data){
// reload javascript variables and html table
$("#my_table").html(data);
}
});
}
});
}
}, 1000);
}).mouseup(function(e) {
clearTimeout(this.downTimer);
});
</script>