HTML表单发送多个 POST 请求。我正在使用jquery.unobtrusive-ajax.js进行异步连接。
我提交表单时,请求已发送到服务器两次。这两个连接的详细信息在浏览器的网络-> XHR选项卡中列出。
感谢您的建议和帮助。
我的HTML表单和JS文件如下:
JS
<script src="/assets/content/js/jquery.unobtrusive-ajax.js"></script>
<script src="/assets/global/scripts/datatable.js" type="text/javascript"></script>
<script src="/assets/global/plugins/datatables/datatables.min.js" type="text/javascript"></script>
<script src="/assets/global/plugins/datatables/plugins/bootstrap/datatables.bootstrap.js" type="text/javascript"></script>
<script src="/assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.js" type="text/javascript"></script>
<script src="/assets/global/plugins/bootstrap-toastr/toastr.min.js" type="text/javascript"></script>
<script src="/assets/content/js/jquery.unobtrusive-ajax.js"></script>
HTML表单
@using (Ajax.BeginForm("UpdateDocument", "Document",
new AjaxOptions()
{
HttpMethod = "POST",
OnBegin = "Document.documentUpdateBegin",
OnSuccess = "Document.documentUpdateSuccess",
OnFailure = "Document.documentUpdateFailure"
}))
{
<div class="form-body">
<input type="hidden" name="ID" value="@Model.DocumentItem.ID" />
<div class="form-group form-md-line-input form-md-floating-label">
<input type="text"
class="form-control"
name="Title" id="title"
autocomplete="off"
maxlength="250"
value="@Model.DocumentItem.Title"
required="required" />
<label for="title_value">Title</label>
<span class="help-block">Max 250 characters</span>
</div>
<div class="form-group form-md-line-input form-md-floating-label">
<label class="control-label col-md-2"
style="padding-left: 0px; margin: 5px 0px; color: #888;">
Durum</label>
<div class="col-md-2">
@Html.CheckBox("IsActive", Model.DocumentItem.IsActive,
new
{
@class = "make-switch",
id = "is_active",
data_on_text = " Aktif ",
data_off_text = " Pasif "
})
</div>
</div>
</div>
<div class="form-actions noborder margin-top-20">
<div class="col-md-2">
<button type="submit" class="btn btn-block blue">UPDATE</button>
</div>
</div>
}
答案 0 :(得分:0)
我找到了解决方法。
JS部分中有两个JavaScript jquery.unobtrusive-ajax.js
文件声明。
删除第二个<script src="/assets/content/js/jquery.unobtrusive-ajax.js"></script>
问题之后。