我有這個表格:
@{ using (Html.BeginForm(@*"MakeOffer", "Product", FormMethod.Post, *@new { id = "offerForm", productId = Model.ProductId, sellerId = Model.SellerId }))
{
@Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
@Html.TextBoxFor(modelItem => modelItem.Price, "{0:#.#}", new { placeholder = "Input your price", id = "offerText", name="offerPrice" })
@Html.HiddenFor(modelItem => modelItem.ProductId)
@Html.HiddenFor(modelItem => modelItem.OffererId)
@Html.HiddenFor(modelItem => modelItem.SellerId)
<input id="offersubmit" type="submit" class="btn" value="Submit" />
}
這是我的 Ajax 函式:
<script>
$(document).ready(function () {
$("#offersubmit").click(function (e) {
if ($(this).valid()true) {
var valdata = $("#offerForm").serialize();
alert(valdata);
$.ajax({
url: "/Product/MakeOffer",
type: "POST",
dataType: 'json',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
data: valdata,
success: $(document).ready(function () {
$('#offerText').val('');
})
})
}
});
});
</script>
現在表單正在傳遞給MakeOffer操作,但我收到 500 錯誤,并且沒有呼叫成功函式。這些是我最后的腳本標簽:
<script src="~/Scripts/jquery-3.6.0.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
uj5u.com熱心網友回復:
您需要洗掉$(document).ready(..)成功回呼的部分。
它應該是
success: function(data)
{
$('#offerText').val('');
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/473830.html
標籤:C# jQuery 网 阿贾克斯 asp.net-mvc
