[英]How to delete data in mysql DB from table td using ajax?
我的目標是使用 AJAX 刪除 mysql db 表中對應的 <td> 數據。 所以我生成了一個包含幾行的表,並且想要一個非特定的行......
PHP 代碼:
<?php
if(isset($_SESSION['login_status'])){
require 'classes/datahandle.class.php';
$data = new Datahandle();
$query = "
SELECT
e.place,
e.id_station,
g.description,
ac.max, ac.min,
ac.mensagem
FROM unit g, tableA ac, station e
WHERE client = '" . $_SESSION['user_id'] . "'
AND ac.unit=g.field
AND ac.id_station=e.id_station
";
$result = $data->selectDataQuery($query);
$numRows = $data->getAffectedRows();
if($numRows > 0){
?>
<table id="consAlerts" border="0" align="center">
<tr>
<td style="text-align: center; color: white; font-weight: bold;">Value 1</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 2</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 3</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 4</td>
<td style="text-align: center; color: white; font-weight: bold;">Value 5</td>
<td colspan="2"></td>
</tr>
<?php
while ($alert = mysql_fetch_array($result)) {
?>
<tr>
<td>
<select class="stationCons" disabled="disabled">
<?php
$query = "SELECT id_station,place FROM station";
$queryResult = $data->selectDataQuery($query);
while($option = mysql_fetch_array($queryResult)){
if($alert['id_station'] == $option['id_station']){
?>
<option value="<?php echo $option['id_station']?>" selected ><?php echo $option['place']?></option>
<?php
}if($alert['id_station'] != $option['id_station']){
?>
<option value="<?php echo $option['id_station']?>"><?php echo $option['place']?></option>
<?php
}
}
?>
</select>
</td>
<td>
<select class="unitCons" disabled="disabled">
<?php
$query = "SELECT field, description FROM unit";
$queryResult = $data->selectDataQuery($query);
while($option = mysql_fetch_array($queryResult)){
if($alert['description'] == $option['description']){
?>
<option value="<?php echo $option['field']?>" selected="selected"><?php echo $option['description']?></option>
<?php
}if($alert['description'] != $option['description']){
?>
<option value="<?php echo $option['field']?>"><?php echo $option['description']?></option>
<?php
}
}
?>
</select>
</td>
<td>
<input type="text" class="consMax" value="<?php echo $alert['max'] ?>"/>
</td>
<td>
<input type="text" class="consMin" value="<?php echo $alert['min'] ?>"/>
</td>
<td>
<input type="text" class="msg" value="<?php echo $alert['mensagem'] ?>"/>
</td>
<td>
<input type="submit" class="delete" value="Delete"/>
</td>
<td>
<input type="submit" class="edit" value="Edit"/>
</td>
</tr>
<?php
}
?>
</table>
<?php
}if ($numRows == 0) {?>
<div style="color:#FFF; font-weight:bold; padding:10px; text-align:center;">Sometext</div>
<?php
}
} else
echo "<meta http-equiv='refresh' content='1; URL=../index.php'>";
?>
JQUERY:
<script type="text/javascript">
<!--
$(document).ready(function() {
$(".delete").click(function(){
//AJAX CALL
$.post("phpValidationScript.php", { station:$(".stationCons").val(), grandeza:$(".unitCons").val(), consMax:$(".consMax").val(), consMin:$(".consMin").val(), msg:$(".msg").val() }, function(data){
alert(data);
});
});
return false;
});
//-->
</script>
我的代碼只刪除了第一行...我怎樣才能引用正確的 td 值? 並將它們傳遞給 ajax?
編輯:我收到此錯誤: TypeError: object is not a function [http://127.0.0.1/somesite/index.ZE1BFD762321E409CEE4AC0B6E841963C0B6E841963C?
錯誤是指下面的代碼:
$.post("validaConsApagar.php", { estacao:$(this)(".estacaoCons").val(), grandeza:$(this)(".grandezaCons").val()}, function(data){...
所以這不是一個 function 那意味着語法錯誤?
使用此運算符。
$.post("phpValidationScript.php", { station:$(this)(".stationCons").val(), grandeza:$(this)(".unitCons").val(), consMax:$(this)(".consMax").val(), consMin:$(this)(".consMin").val(), msg:$(this)(".msg").val() }, function(data){
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.