简体   繁体   English

我无法使用jQuery提交表单

[英]I am not able to submit a form using jquery

I am not able to submit the code I am writing using jQuery. 我无法提交使用jQuery编写的代码。 This is being used in congestion with JSP on the Hybris platform. Hybris平台上的JSP经常使用此功能。

The button click event is happening as expected, but for some reason, the form is not being submitted. 按钮单击事件正在按预期的方式发生,但是由于某种原因,表单尚未提交。

//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>

I am not able to find any reason why the form is not submitting. 我找不到表单未提交的任何原因。 I expect it to make a network call for action URL. 我希望它能引起网络呼吁采取行动。

在Hybris中,每个post方法都必须具有CSRF令牌,您需要确保已通过。

add name="MyAddressForm" in your form tag form标签中添加name="MyAddressForm"

then run this. 然后运行这个。

$("#jsContinueButton").on("click",function(e){
  e.preventDefault();
  document.forms["myAddressForm"].submit();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM