[英]I am not able to submit a form using jquery
我无法提交使用jQuery编写的代码。 Hybris平台上的JSP经常使用此功能。
按钮单击事件正在按预期的方式发生,但是由于某种原因,表单尚未提交。
//option-1
$("#jsContinueButton").on("click",function(e){
e.preventDefault();
$("#MyAddressForm").submit(function(event){
event.preventDefault();
});
});
//option-2
$("#jsContinueButton").on("click",function(e){
e.preventDefault();
$("#MyAddressForm").submit();
});
<form:form action="/cart/update" method="post" commandName="MyAddressForm" id="MyAddressForm">
<div class="selected-address-data-container" style="display: none;">
<input type="hidden" data-old="" name="line1" id="address1" value="address 1" />
<input type="hidden" data-old="" name="line2" id="address2" value="address 2" />
<input type="hidden" data-old="" name="suburb" id="suburb" value="suburb" />
<input type="hidden" data-old="" name="townCity" id="towncity" value="city name" />
<input type="hidden" data-old="" name="postcode" id="postcode" value="postcode" />
<input type="hidden" data-old="" name="meshblock" id="meshblock" value="" />
<input type="hidden" data-old="" name="gps_lat" id="gps_lat" value="123.12" />
<input type="hidden" data-old="" name="gps_long" id="gps_long" value="123.23" />
<input type="hidden" data-old="" name="dpid" id="dpid" value="" />
<input type="hidden" data-old="" name="sufi" id="sufi" value="" />
<input type="hidden" data-old="" name="rdNumber" id="rdNumber" value="" />
<input type="hidden" data-old="" name="rural" id="rural" value="false" />
<input type="hidden" data-old="" name="boxType" id="boxType" value="" />
</div>
</form:form>
我找不到表单未提交的任何原因。 我希望它能引起网络呼吁采取行动。
在Hybris中,每个post方法都必须具有CSRF令牌,您需要确保已通过。
在form
标签中添加name="MyAddressForm"
然后运行这个。
$("#jsContinueButton").on("click",function(e){
e.preventDefault();
document.forms["myAddressForm"].submit();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.