I'm converting a JSP to use ajax to post to the action but the ActionForm is blank when the request comes through. I am not sure what is going on as this should be working fine from what I've read. If I remove the ajax the page submits just fine. UPDATE: When debugging, the data var shows the correct string for the form. Also I've added the Struts config.
HTML:
<html:form action="/saveSomething" method="POST"> ... </html:form>
JS:
$('form[name="form_name"]').submit(function(e) {
e.preventDefault();
var url = $('form[name="form_name"]').attr('action');
var data = $('form[name="form_name"]').serialize();
var posting = $.post(url, data);
});
Struts config:
<action name="form_name" path="/notesPage" scope="request" type="com.action.Action" validate="false" input="/jsp/notesPage.jsp">
<forward name="success" path="/jsp/notesPage.jsp" />
</action>
This is Struts 1 and as I said, if I remove the JS form submit method everything works fine so I don't think it's my mapping or anything to do with Struts.
Your form does not have a name attribute:
so instead you can do this:
And i hope you are putting this code in document ready block.