使用 Ajax.BeginForm 和 Jquery.Unobtrusive 请求发送多个
Request Sends More Than One Using Ajax.BeginForm and Jquery.Unobtrusive
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>
}
我找到了解决方案。
JS部分有两个javascriptjquery.unobtrusive-ajax.js
文件声明。
我去掉第二个后<script src="/assets/content/js/jquery.unobtrusive-ajax.js"></script>
问题就解决了
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>
}
我找到了解决方案。
JS部分有两个javascriptjquery.unobtrusive-ajax.js
文件声明。
我去掉第二个后<script src="/assets/content/js/jquery.unobtrusive-ajax.js"></script>
问题就解决了