[英]Jquery and php delete row without refresh page
I am trying to make a jquery delete div function but i have one problem. 我试图使一个jQuery删除div功能,但我有一个问题。
When i press submit button div was not removed and also page refreshed. 当我按下提交按钮时,div并没有被删除,页面也刷新了。 How can i do without refresh page.
没有刷新页面怎么办?
This is my jquery function code: 这是我的jQuery函数代码:
$(document).ready(function () {
$('.ilan_alani').on('click', '.showmenu', function(e) {
var $ilan_alani = e.delegateTarget;
$('.note_area', $ilan_alani).toggle('puff');
$('.showmenu', $ilan_alani).hide();
$('.hidemenu', $ilan_alani).show();
})
.on('click', '.hidemenu', function(e) {
var $ilan_alani = e.delegateTarget;
$('.note_area', $ilan_alani).toggle("puff");
$(".hidemenu", $ilan_alani).hide();
$(".showmenu", $ilan_alani).show();
});
$('.ilan_alani .psdlt').click(function() {
$(this).parents('.ilan_alani').animate({ opacity: 'hide' }, 'slow');
});
});
and also HTML code here: 还有HTML代码:
<div class="ilan_alani">
<div class="note_area">
<div class="hidemenu">
<form method="post">
<input type='submit' name='Delete' value='Delete' class='psdlt' />
</form></div>
</div>
<div class="test"></div>
<div class="showmenu">Shows</div>
</div>
<div class="ilan_alani">
<div class="note_area">
<div class="hidemenu"> <form method="post">
<input type='submit' name='Delete' value='Delete' class='psdlt' />
</form></div>
</div>
<div class="test"></div>
<div class="showmenu">Show</div>
</div>
What I want. 我想要的是。 Div without refreshing the
ilan_alani
is deleted. 不刷新
ilan_alani
Div被删除。
You are using form
tag and submit button
which submit your form
on click try to remove form
tag and button type as submit
您正在使用
form
标签和submit button
,单击时提交您的form
,尝试删除form
标签和按钮类型为submit
<form method="post">
<input type='submit' name='Delete' value='Delete' class='psdlt' />
</form>
to 至
<input type='button' name='Delete' value='Delete' class='psdlt' />
What you want to do is make a php page apart from this, 您想要做的是使php页面与此分开,
which deletes a row based on your get or post value 这会根据您的获取或发布值删除一行
something like this (with your own security and db connection added) 这样的事情(添加您自己的安全性和数据库连接)
<?php
$db->query('DELETE FROM yourtable WHERE id = ' . $_POST['rowId']);
?>
Than with your javascript button or whatever has the click event, 比起您的javascript按钮或具有点击事件的任何东西,
you add the ajax to call the page above. 您添加ajax来调用上面的页面。
So this will look something like this: 所以这看起来像这样:
$('#someElement').click(function() {
id = the id of the row you want deleted;
$.ajax({
url: "url to the page above here",
type: "post",
data: {
"rowId" : id,
}
}).done(function() {
alert('row deleted');
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.