Asp.net Ajax多表单不工作
我在一页中有许多表格。我的脚本工作,但只有一次,随后的请求发送到服务器,但不再工作添加结果。 我想添加一些评论ajax方法一直有效。Asp.net Ajax多表单不工作,asp.net,ajax,forms,Asp.net,Ajax,Forms,我在一页中有许多表格。我的脚本工作,但只有一次,随后的请求发送到服务器,但不再工作添加结果。 我想添加一些评论ajax方法一直有效。 请提供任何帮助。您可以尝试创建一个函数,该函数在创建事件时接收参数或ID 例如: <div class="row"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> &l
请提供任何帮助。您可以尝试创建一个函数,该函数在创建事件时接收参数或ID 例如:
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div id="com-@Model.demot.DemotId">
@Html.Partial("_Comments", Model.demot.Comments)
</div>
@using (Html.BeginForm("AddComments", "Demot", new { DemotId = @Model.demot.DemotId}, FormMethod.Post, new { data_ajax = true, data_ajax_target = "com-" + @Model.demot.DemotId }))
{
@Html.AntiForgeryToken();
<div class="error-summary-centred">
@Html.ValidationSummary()
</div>
<div id="add">
<table id="albumedit-address-table">
<tr>
<td>@Html.TextBoxFor(o => o.comment, new { @class = "comment", placeholder = "Comment", value = "" })</td>
<td>@Html.ValidationMessageFor(o => o.comment)</td>
</tr>
</table>
</div>
}
</div>
</div>
<script>
$(function () {
$('form').on('submit', function (e) {
var $form = $(this);
var $target = $form.attr('data-ajax-target');
$.ajax({
url: $(this).attr("action"),
type: $(this).attr("method"),
data: $(this).serialize(),
success: function (result) {
var $newContent = $(result);
$($('#' + $target)).replaceWith($newContent);
$newContent.effect("highlight");
$form.each(function(){
this.reset();
});
}
});
e.preventDefault();
});
});
</script>
你能添加相关的HTML和更多你想要实现的细节吗?
<script>
$(function() {
$('form').on('submit', function(e) {
var $form = $(this) functionAJAX(form)
})
});
functionAJAX() { /*His Code here*/ }
</script>