[英]On Span Click - Insert rows into MySQL with page refresh
I've got a page where I display rows from MySQL table. 我有一个页面,其中显示MySQL表中的行。
while($row2 = $result2->fetch_assoc()) { ?>
<p>
<span class="label label-primary">
<?php echo ($row2["miasto"]); ?>
</span>
<span class="label label-primary delete" id="<?php echo ($row2["miasto"]); ?>"><i class="fa fa-times"></i></span>
</p>
on a span click .delete I would like to get this row deleted from a database and page refreshed without those rows and with alert to be present. 在跨度上单击.delete,我想从数据库中删除该行,并刷新页面而没有那些行并显示警报。
I'm able to do a on click action in Jquery: 我可以在Jquery中执行点击操作:
$(document).ready(
function(){
$(".delete").click(function () {
$.post( "miastousun.php", { mdu: (this.id)} );
and than on php of miastousun.php: 并且比在miastousun.php的php上:
$sql = "DELETE FROM miasta_zmiany WHERE Miasto_dodaj='".($_POST['mdu'])."";
but does not seem to work. 但似乎不起作用。 What I'm doing wrong? 我做错了什么?
Try this ajax code. 试试这个ajax代码。
$( document ).on( 'click', '.delete', function() {
var thisId = $(this).attr('id');
$.ajax({
type: 'POST',
url: 'miastousun.php?mdu='+thisId,
success: function(data){
alert('Message something');
},
error: function(errorThrown){
alert(errorThrown);
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.