我有一個論壇,允許用戶編輯和刪除他的評論,我已經定義了一個「編輯」按鈕,通過點擊鼠標可以打開一個模式,並在該模式用戶被允許訪問他/她以前發送的數據,我寫了一個ajax來定位這些字段,並在用戶點擊「編輯」按鈕時更新它們,代碼完全有意義,但到目前爲止該功能不會使用戶點擊,模式下降,他/她發佈的任何內容都會顯示在字段中,並且模式底部會出現一個「編輯」按鈕,該按鈕負責更改並更新數據。這裏是模態代碼:Ajax沒有更新數據
<button id="btn-btnedit" class="btn btn-primary " data-toggle="modal" data-target="#myModal<?php echo $list['id']; ?>">
Edit <i class="fa fa-pencil-square-o"></i>
</button>
<!-- Modal -->
<div class="modal fade" id="myModal<?php echo $list['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div class="container">
<form style="width: 550px;" action="" method="post" id="signin-form<?php echo $list['id']; ?>" role="form">
<input type="hidden" name="commentID" value="<?php echo $list['id']; ?>">
<div class="from-group">
<label for="title">Title: </label>
<input class="form-control" type="text" name="title" id="txttitle" value="<?php echo $list['title']; ?>" placeholder="Page Title">
</div>
<div class="from-group">
<label for="label">Label: </label>
<input class="form-control" type="text" name="label" id="txtlabel" value="<?php echo $list['label']; ?>" placeholder="Page Label">
</div>
<br>
<div class="from-group">
<label for="body">Body: </label>
<textarea class="form-control editor" name="body" id="txtbody" row="8" placeholder="Page Body"><?php echo $list['body']; ?></textarea>
</div>
<br>
<input type="hidden" name="editted" value="1">
<br>
<br>
<input type="submit" id="btnupdate" value="Edit">
</form>
</div>
</div>
,你可以看到我已經指派「editted」我的「name」屬性,這就是後來的上用於調用數據庫中的查詢,SQL代碼如下:
case 'postupdate';
if(isset($_GET['editted'])){
$title = $_GET['title'];
$label = $_GET['label'];
$body = $_GET['body'];
$action = 'Updated';
$q = "UPDATE posts SET title ='".$title."', label = '".$label."', body = '".$body."' WHERE id = ".$_GET['commentID'];
$r = mysqli_query($dbc, $q);
$message = '<p class="alert alert-success"> Your Post Is Succesfully '.$action.'</p>' ;
}
這裏是ajax代碼片段;
$('#btnupdate').click(function() {
var tempTitle = $('#txttitle').val();
var tempLabel = $('#txtlabel').val();
var tempBody = $('#txtbody').val();
var tempUrl = "index.php?page=postupdate"+"&title="+tempTitle+"&label="+tempLabel+"&body="+tempBody+"&commentID=30&editted=1";
$.get(tempUrl);
});
我假設有關於這個部分的代碼沒有什麼進步,我失去了一些東西很簡單,任何代價的高度讚賞:)
你應該做一個帖子,而不是一個get。內容可能會很長。 (大小寫注入) – Daan 2014-09-23 14:20:22
你好大安,在發佈之前嘗試過,好吧,這比我想的方法還要多 – 2014-09-23 14:23:00
你對.get()的結果不做任何事情,你沒有通過回調... – FrancescoMM 2014-09-23 14:23:16