在开发过程中,肯定会遇到表单提交传值。以前的做法是在页面放一个隐藏的input标签,给个
name然后放个value,提交的时候将这个value提交到后台。但是这种方式会很不安全。
所以,就有了新的方式解决表单提交传值的问题:
<form style="display:none" method="get">
<input name="addressId" type="hidden" value="@ViewBag.AddressId" />
<input name="cartIds" type="hidden" value="@ViewBag.CartIds" />
</form>
<script>
$(‘.paytbn‘).click(function () {
var cartIds = $(‘form input[name=cartIds]‘).val();
var addressId = $(‘form input[name=addressId]‘).val();
var referNo = $(‘.order-referno‘).val();
var logistics = [];
$.each($(‘select.logistics‘), function () {
var table = $(this).parents(‘.goods-table‘);
var map = table.attr(‘data-wareid‘) + ‘|‘ + $(this).val();
logistics.push(map);
});
if (logistics.length < 1) {
ZTLayer.showTips(‘@T("Order.PleaseChooseSendway")‘, 2);
return;
}
$.post(‘@Url.Action("SubmitOrder")‘, { cartIds: cartIds, addressId: addressId, logistics: logistics, referNo: referNo },
function (data) {
if (data.flag) {
location.href = ‘@Url.RouteUrl("PaymentOrder")‘ + "?orderNos=" + data.msg;
} else {
if (data.redirect) {
location.href = data.redirect;
} else {
ZTLayer.showTips(data.msg, 2);
}
}
});
});
原文地址:https://www.cnblogs.com/opts/p/8993651.html