i have the following script in my ASP.NET MVC Project :
$(function () { var ajaxFormSubmit = function () { var $form = $(this); var options = { url: $form.attr("action"), type: $form.attr("method"), data: $form.serialize() }; $.ajax(options).done(function (data) { var $target = $($form.attr("data-otf-target")); var $newHtml = $(data); $target.replaceWith($newHtml); }); return false; }; $("form[data-otf-ajax='true']").submit(ajaxFormSubmit); }); why this fonction executes just once ? this function is for updating a list of objects , here is the form on the razor view :
<form method="get" action="@Url.Action("Index")" data-otf-ajax ="true" data-otf-target="#RestaurantList"> <input type="search" name="searchTerm" /> <input type="submit" value="Search By Name" /> </form> <div id="RestaurantList"> @Html.Partial("_Restaurants") </div>
RestaurantListdiv....maybe it gots overwritten by the ajax call.buttonand execute the above function using Jquery'sclick(function)and do let me know..