通过提交“点击”触发器提交两次HTML表单 [英] HTML form being submitted twice via submit 'click' trigger

查看:228
本文介绍了通过提交“点击”触发器提交两次HTML表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉发布了类似于近100个问题的问题。我读了很多,尝试了几个解决方案,但无法解决我的问题或完全将问题的答案与我的问题联系起来。

I am sorry for posting a question which is similar to almost 100 questions on SO. I read a lot of them, tried a couple of solutions but was not able to either fix my problem or completely relate the answers to my issue.


  1. 我有一个表格带有一个动作,输入类型。

  2. 我有一个<输入类型=提交> 以该格式。

  3. 我需要通过触发'点击'关于此输入。我做的是 $('#imageUploadSubmit')。click();

  1. I have a form with an action, type post.
  2. I have a <input type="submit"> in that form.
  3. I need to submit this form by triggering a 'click' on this input. Which I do by $('#imageUploadSubmit').click();



<我不应该绕过点击这个提交按钮,因为还有其他与此相关的事件,这些事件是必不可少的,来自Struts jQuery。因此我无法直接提交表单。

I am not supposed to bypass 'clicking' this submit button because there are other events associated with this, which are essential and come from Struts jQuery. Hence I cannot submit the form directly.

问题:我的表单 action (uploadImage)被调用两次。我无法阻止它。

Problem : my form action (uploadImage) is being called twice. And I am unable to prevent it.

相关的JSP:

<s:form id="image-upload-form" action="uploadImage" method="post" enctype="multipart/form-data">
    <s:file name="userImage" label="User Image" id="userImageFile" />
    <input type="hidden" id="idForUpload" name="idForUpload" value="<s:property value="imageUploadReqAttrib.imageName" />" />
    <sj:submit id="imageUploadSubmit" value="Select Image" targets="previewImageDiv" 
        indicator="indicator" onBeforeTopics="before" onCompleteTopics="complete" style="display:none;"/>
</s:form>

和生成的Html(带有相关元素)

and the generated Html (with relevant elements)

<form id="image-upload-form" name="image-upload-form" action="/foo/uploadImage.action" method="post" enctype="multipart/form-data">
      <input type="file" name="userImage" value="" id="userImageFile"></td>
      <input type="hidden" id="idForUpload" name="idForUpload" value="1371711900.jpg">
      <input type="submit" id="imageUploadSubmit" value="Select Image" style="display:none;">
</form>

有没有办法可以找出在此之后及之后触发的所有事件点击?在Chrome Inspector中? Fiddler?

Is there a way by which I could find out all the events that are being triggered on and after that click? In Chrome Inspector? Fiddler?

我很感激任何指针。谢谢。

I would appreciate any pointers. Thank You.

推荐答案

谷歌搜索后,这似乎是问题所在:所有版本> 2.1.0 of struts2- jquery-plugin有这个问题。现在,我不确定问题是我使用插件的方式还是实际上是一个bug。社区中的一个漏洞让我觉得这是一个错误。

After googling more, this is what seems to be the problem : All versions > 2.1.0 of struts2-jquery-plugin have this issue. Now, I'm not sure if the problem is the way which I am using the plugin or if it is actually a bug. An open bug in the community makes me feel that this is a bug.

所以,我从struts2-jquery-3.3迁移到了struts2-jquery-2.1.0:

So, I moved from struts2-jquery-3.3 to struts2-jquery-2.1.0 :|

这篇关于通过提交“点击”触发器提交两次HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆