您好,我编写了一个jquery代码,在其中单击button时,我将使用jquery Submit()函数提交表单。 但是当表单提交时,网址已更改,我不想更改我的网址,我也不想使用ajax,因为我需要刷新页面以获取最新数据。提交后排。
下面是该网址的代码段和图片
$("#itemupdateModelForm").click(function(event) {
event.preventDefault(); // avoid to execute the actual submit of the form.
return false;
});
$(".itemupdateButton").click(function(event) {
event.preventDefault(); // avoid to execute the actual submit of the form.
var form = $('#itemupdateModelForm');
var url = form.attr('action');
var newUrl = url + currentRowItemId;
form.attr('action',newUrl);
$( "#itemupdateModelForm" ).submit();
return false;
});
提交表格后
我希望在提交没有ajax的表单后,我的网址保持不变 下面是模型表格
<div class="col-xl-8 col-lg-7">
<div class="itemUpdateTaskForm">
<form th:action="@{/category/{id}/item/(id=${categoryId})}" th:method="post" th:object=${updateItemModel} id="itemupdateModelForm">
<div class="modal fade" id="updateTaskModel" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel" th:text="${categoryName}">Edit</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="title">Current Stock Quantity:</label>
<input th:field="*{currentStockQuantity}" value="" type="text" class="form-control" id="crntstckqnty" name="currentstockquantity" placeholder="currentstockquantity" readonly="readonly"/>
</div>
<div class="form-group">
<label for="title">Item Price:</label>
<input th:field="*{currentPurchasePrice}" value="" type="text" class="form-control" id="current_item_price" name="current_item_price" placeholder="Current Item Price" />
</div>
<div class="form-group">
<label for="status">Unit:</label>
<select id="unit" class="form-control" name="unit" th:field=*{unit}>
<option th:each="status : ${T(com.inventory.domain.ItemWeightUnit).values()}"
th:text="${status}" th:value="${status}">
</option>
</select>
</div>
<div class="form-group">
<label for="title">Take Item:</label>
<input th:field="*{updatedQuantity}" value="" type="text" class="form-control" id="updatedQuantity" name="updatedQuantity" placeholder="updateQuantity"/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<input type="button" class="btn btn-primary itemupdateButton" value="save"/>
</div>
</div>
</div>
</div>
</form>
</div>
答案 0 :(得分:1)
答案 1 :(得分:0)
如果您不想使用AJAX,则需要完成GET / POST请求。
最简单的方法是从接收表单数据的页面重定向到原始页面。
也就是说,一旦/category/1/item/9
处理了表单数据,请重定向到/categ/Masala
。这样,您就可以拥有最新数据的刷新也将完成。
另一种方法是使用与表单相同的URL处理数据,但使用不同的方法(POST而不是GET)处理数据,或者使用之类的逻辑(如果可用)处理数据,如果没有,显示表单,但仍然需要重定向或始终呈现页面。