嗨,我有表,我正在执行内联编辑,我正在尝试使用单击按钮(即:img)将值更新到数据库,我尝试使用 onclick 功能但它的编辑值,它显示
“ value=undefined&rowid=undefined&field=undefined"
,
下面是我的代码。可以一个人指导我如何做到这一点。谢谢
我的阿贾克斯
$(document).ready(function () {
$('td.edit').click(function (e) {
var $target = $(e.target);
if ($target.is('#editbox')) {
return;
}
$('.ajax').html($('.ajax input').val());
$('.ajax').removeClass('ajax');
$(this).addClass('ajax');
$(this).html('<input id="editbox" size="5" type="text" value="' + $(this).text() + '">');
$('#editbox').select();
}
);
$('td.edit1 img').on('click', function () {
arr = $(this).parent().attr('class').split(' ');
$.ajax({
type: "POST",
url: "clientnetworkpricelist/update.php",
data: "value=" + $('.ajax input').val() + "&rowid=" + arr[1] + "&field=" + arr[2],
success: function (data) {
$('.ajax').html($('.ajax input').val());
$('.ajax').removeClass('ajax');
}
});
});
$('#editbox').live('blur', function () {
$('.ajax').html($('.ajax input').val());
$('.ajax').removeClass('ajax');
});
});
我的 HTML
<?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = 'fms';
$dbPassword = 'xxxxxxxx';
$dbDatabase = 'fms';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");
$clientid=$_GET['clientid'];
$region=$_GET['region'];
$clientid_query="";
$region_query="";
if($clientid!=""){
$clientid_query="WHERE clientid = '$clientid'";}
else{
if($region!=""){
$region_query="WHERE region = '$region'";}
else{
$region_query="";
}
}
$sql="SELECT * FROM clientnetworkprice"." ".$clientid_query or $region_query ;
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result))
{
if($alt == 1)
{ echo '<tr class="alt">';
$alt = 0;
}
else
{
echo '<tr>';
$alt = 1;
}
echo ' <td class=" '.$rows["id"].'">'.$rows["clientid"].'</td>
<td id="CPH_GridView1_clientid" class=" '.$rows["id"].'">'.$rows["region"].'</td>
<td id="CPH_GridView1_country" class=" '.$rows["id"].'">'.$rows["country"].'</td>
<td id="CPH_GridView1_networkname" class=" '.$rows["id"].'">'.$rows["networkname"].'</td>
<td id="CPH_GridView1_mcc" input type="text" name="mcc" id="mcc" class=" '.$rows["id"].'">'.$rows["mcc"].'</td>
<td id="CPH_GridView1_mnc" input type="text" name="mnc" id="mnc" class="'.$rows["id"].'">'.$rows["mnc"].'</td>
<td id="CPH_GridView1_mnp" class="edit mnp '.$rows["id"].'">'.$rows["mnp"].'</td>';
$ColumnNames = mysql_query("SELECT column_name FROM information_schema.COLUMNS WHERE table_name = 'clientnetworkprice' AND column_name NOT
IN ('id','clientid','region', 'country', 'networkname', 'mcc', 'mnc', 'mnp','clientprice','supplierroute'
)") or die("mysql error");
$columnArray=array();
$i=0;
while($rows1=mysql_fetch_array($ColumnNames))
{
$columnArray[]=$rows1[0];
echo '<td id="CPH_GridView1_xxx" width="0px;" class="edit '.$columnArray[$i].' '.$rows["id"].'">'.$rows[$columnArray[$i]].'</td>';
$i++;
}
echo ' <td id="CPH_GridView1_clientprice" class="edit clientprice '.$rows["id"].'">'.$rows["clientprice"].'</td>
<td id="CPH_GridView1_supplierroute" class="edit supplierroute '.$rows["id"].'">'.$rows["supplierroute"].'
</td>
<td class="edit1"><img src="/image/Picture1.png" style="margin:0 0 0 6px;;cursor:pointer" ></td>'
;
echo '</tr>';
}
?>