我正在使用下面的代码使用 jQuery 和 AJAX 来更新我的数据库。
删除工作完美,但编辑功能不起作用。如何从每个输入字段中获取值?
<ol class="update">
<?php
$ss = mysql_query ("SELECT * FROM users_channels WHERE u_id='$uid'");
while ($chann = mysql_fetch_assoc($ss)) {
echo'
<li>
<input name="channelName" type="text" id="channelName" style="float:left; width:300px; border:1px solid #CCC;" value="'.$chann['channel_name'].'" />
<a href="#" id="'.$chann['id'].'" class="delete_button"><span id="rcolor">Delete</span></a>
<a href="#" id="'.$chann['id'].'" cvalue="'.$chann['channel_name'].'" class="save_button"><span id="gcolor">Save</span></a>
</li>';
}
?>
</ol>
Javascript代码:
$(document).ready(function() {
$(function() {
$(".save_button").click(function() {
var id = $(this).attr("id");
var cvalue = $(this).attr("cvalue");
var dataStringe = 'id=' + id + '&cvalue=' + cvalue;
var parent = $(this).parent();
alert(cvalue);
$.ajax({
type: "POST",
url: "update_channel.php",
data: dataStringe,
cache: false,
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'}, 300).animate({ opacity: 0.35 }, "slow");
},
success: function() {
//parent.slideUp('slow', function() {$(this).remove();});
}
});
return false;
});
});
});