سؤال

Here is my code:

<s:form
     id="deployChapters%{#chapterTree.nodeId}" 
     action="%{deployChapterUrl}"
     theme="simple"
     method="POST">
     <s:hidden name="nodeId" value"%{#chapterTree.nodeId}" />
</s:form>

I submit this form with Ajax. With Firefox, the hidden field nodeId is not sent. It is with Chrome or IE.

How can I ask FF to send the hidden field?

هل كانت مفيدة؟

المحلول 2

Finally, here is the solution I came up with:

  • I detect when the form is submitted and I programmatically add the hidden field to the form.

نصائح أخرى

Add a submit button to the form, change the id attribute so easily select it with jQuery and attach handler

<s:form
     id="deployChaptersForm" 
     action="%{deployChapterUrl}"
     theme="simple"
     method="POST">
     <s:hidden name="nodeId" value"%{#chapterTree.nodeId}" />
     <s:submit/>
</s:form>
<script type="text/javascript"> 
 // Attach a submit handler to the form
 $("#deployChaptersForm").submit(function(event) {
   //Stop form from submitting normally
   event.preventDefault();
   //Get some values from elements on the page:
   var $form = $(this),
   value = $form.find("input[name='nodeId']").val(),
   url = $form.attr("action");
   //Send the data using post
   var thePost = $.post(url, {nodeId: value});
   //Handle results in data
   thePost.done(function(data) {
    alert(data);
   });
 });
</script>

Struts/JSP code (that is server-side code) doesn't depend on client browser to render HTML.

So, it is your Javascript function, which send the Ajax request (post or get) with data based on the html form data, that has a issue.

Please inspect/debug, your Javascript code to fix it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top