我的代碼正常工作。它提交數據而不重新加載。只有在提交時重新載入此表格或div
但我想重新加載只有這種形式或這個div像往常一樣提交。
總之,我想提交這個表單就像它發生type =「submit」一樣。我不想阻止與js的負載,但只加載此表單而不是其他div或整個頁面。
我應該在這裏寫什麼?
.done(function(data){
//reload div or form only
})
<div id="reply-box">
<div class="form-group">
<form action="" method="post" id="reply" enctype="multipart/form-data" style="width: 85%;" >
<div class="input-group">
<input type="file" name="image2" class="file" id="imgInp"/>
<span class="input-group-btn">
<button class="browse btn btn-primary input-md" type="button" ><i class="glyphicon glyphicon-picture"></i>I</button>
</span>
<input type="text" placeholder="say something" class="form-control" id="comment" name="comment" required/><br/>
<span class="input-group-btn">
<button class="btn btn-info" type="submit" >submit</button>
</span>
</div>
<div>
<img id="blah" src="/final/images/blank.jpg" style=" width:7%; float:left; " />
</div>
</form>
</div>
<script type="text/javascript">
$(document).ready(function() { \t
\t
\t // submit form using $.ajax() method
\t
\t $('#reply').submit(function(e){
\t \t
\t \t e.preventDefault(); // Prevent Default Submission
\t \t
\t \t $.ajax({
\t \t \t url: 'reply.php?slug=<?=$page_id?>',
\t \t \t type: 'POST',
\t \t \t
\t \t data: new FormData(this),
\t \t \t contentType: false,
\t cache: false,
\t \t \t processData:false,
\t \t
\t \t })
\t \t .done(function(data){
\t \t
// here i want to refresh only the form or the div like normally happens on submit
\t \t
\t \t \t
\t \t })
\t \t .fail(function(){
\t \t \t alert('Ajax Submit Failed ...'); \t
\t \t });
\t });
\t
});
</script>
一般'IFRAME '不用於表單。 – Jaber