无法使用php代码点火器和jquery进行内联编辑。无法更新数据库中的表值
这是我的edit_table.php,在其中生成动态表,并通过单击函数尝试更新数据库无法使用php代码点火器和jquery进行内联编辑。无法更新数据库中的表值,php,jquery,angularjs,ajax,codeigniter,Php,Jquery,Angularjs,Ajax,Codeigniter,这是我的edit_table.php,在其中生成动态表,并通过单击函数尝试更新数据库 <script> function table_edit(btn) { var id=btn.id; if(btn.value=="Edit") { document.getElementById('college_id'+id).setAttribute("contenteditable" , "true"); document.g
<script>
function table_edit(btn)
{
var id=btn.id;
if(btn.value=="Edit")
{
document.getElementById('college_id'+id).setAttribute("contenteditable" , "true");
document.getElementById('name'+id).setAttribute("contenteditable" , "true");
//document.getElementById('university_id'+id).removeAttribute("Readonly");
document.getElementById('university_id'+id).setAttribute("contenteditable" , "true");
document.getElementById(id).value="Save";
return false;
}
if(btn.value=="Save")
{
document.getElementById('name'+id).removeAttribute("contenteditable");
document.getElementById('college_id'+id).removeAttribute("contenteditable");
// document.getElementById('university_id'+id).setAttribute("Readonly" , "readonly");
document.getElementById('university_id'+id).removeAttribute("contenteditable");
document.getElementById(id).value="Edit";
var newuniversity_id=document.getElementById('university_id'+id).innerHTML;
var newcollege_id=document.getElementById('college_id'+id).innerHTML;
var newname=document.getElementById('name'+id).innerHTML;
alert(newname+" "+newcollege_id+" "+newuniversity_id+" "+id);
var dataString = 'name1=' + name + '&university_id=' + newuniversity_id + '&college_id=' + newcollege_id + '&id=' + id;
$.ajax({
type: "POST",
url: "update_table_data",
data: dataString,
success: function(html) {
alert("ajax calling done");
}
});
return true;
}
}
function table_update(){
//document.getElementById("edit_rows").value="Save"
alert("Working!");
}
</script>
<?php
function test()
{
echo "<script>alert('hello');</script>";
} ?>
<div id="page-content-wrapper">
<div class="container-fluid">
<a href="#menu-toggle" class="btn btn-default" id="menu-toggle"><i class="fa fa-bars"></i> <span>Menu</span></a>
<div class="content-block">
<div class="login-sign forgot_pass login forgot text-center">
<!-- <form action="<?php echo base_url(); ?>edit_table" method="post" accept-charset="utf-8"> -->
<div class="login-signup-head">Edit Table</div>
<table>
<tbody>
<thead>
<tr class="tredit">
<!-- <th width="10"></th> -->
<th> Id </th>
<th > University Id </th>
<th > Name </th>
<th > College Id </th>
<th width="100"> </th>
</tr>
</thead>
<tbody>
<?php
foreach($student_data as $row){
?>
<tr class="tredit" id="row_edit">
<td><?php echo $row['id']; ?></td>
<td id="university_id<?php echo $row['id']; ?>" ><?php echo $row['university_id']; ?></td>
<td id="name<?php echo $row['id']; ?>" ><?php echo $row['name']; ?></td>
<td id="college_id<?php echo $row['id']; ?>" > <?php echo $row['college_id']; ?></td>
<td><input type='button' class='editable' onclick=" return table_edit(this)" value='Edit' id= "<?php echo $row['id']; ?>">
<input type='button' class='tabledelete' onclick="table_update()" value='Delete' ></td>
</tr>
<?php
}
?>
</div>
</div>
</div>
<!-- </form> -->
</div>
</div>
</tbody>
</table>
最后,这是更新查询的模型
public function update_table($university_id,$college_id,$name,$id) {
$data = array('University Id' => $university_id, 'name' => $name, 'College Id' => $college_id);
$this->db->where('id', $id);
$this->db->update('college', $data);
}
但当我保存并刷新页面时,表中不会发生任何更改。我的问题是,当我从“保存”按钮更新数据库时,数据库没有更新。首先: 格式化您的代码,这必须是干净的,易于阅读 对于ajax调用,您不需要使用路由url,它在后台工作,您可以这样使用: put:
var base\u url=''
在标题菜单中,或在主题中使用的上方位置
然后进行如下ajax调用:
$.ajax({
type: "POST",
url: base_url+"youController/yourAction",
data: dataString,
success: function(html) {
alert("ajax calling done");
}
});
您需要缩小问题范围(和代码…),我不知道您在问什么。请稍等。让我修改我的代码。抱歉耽搁了!请看一看描述并仔细阅读。所以问题是我有一个html格式的表,我基本上从数据库中获取了它的值&我已经使它可以编辑,但不能在数据库中更新它。在这方面你能帮我吗?
$.ajax({
type: "POST",
url: base_url+"youController/yourAction",
data: dataString,
success: function(html) {
alert("ajax calling done");
}
});