问题
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.
- I have a
form
with an action, type post. - I have a
<input type="submit">
in that form. - I need to submit this form by triggering a '
click
' on this input. Which I do by$('#imageUploadSubmit').click()
;
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.
Problem : my form action
(uploadImage) is being called twice. And I am unable to prevent it.
Relevant piece of 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>
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>
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.
回答1:
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.
So, I moved from struts2-jquery-3.3 to struts2-jquery-2.1.0 :|
来源:https://stackoverflow.com/questions/11744773/html-form-being-submitted-twice-via-submit-click-trigger