1

I am having a slight issue trying to implement smoothState.js (https://github.com/miguel-perez/smoothState.js) with my JSP backend. I get this error when I try to submit the form for the first time. The second time I press submit it goes through, I have no idea what is the cause of it but found a possible clue.

 POST http://localhost:8080/internal/inquiry/[object%20HTMLInputElement] 404 (Not Found)

It only happens on the forms that have a hidden input with name="action". For example if I have this in my form:

 <input type="hidden" name="action" value="<%=Inquiry.CREATE_ACTION_DESCRIPTION_DATA%>" />

This is the code for my submit.

$(document).ready(function(){


 $('#descriptionData').parsley().on('form:success', function() {
    var $form = $("#descriptionData");
    var action = "<%=Inquiry.CREATE_ACTION_DESCRIPTION_DATA%>"; 
    var formUrl = '/inquiry.do?action=' + action + '&ajax=1';

    $form.submit(function (ev) {
        $.ajax({
         type     : "POST",
         url      : formUrl,
         data     : $form.serializeArray(),
         async    : true,
         success  : function(data) {
                var smoothState = $('#main-cont').smoothState().data('smoothState');
                smoothState.load(data.redirectPage);
            }
        });

        ev.preventDefault();
    });
});

});

Any help would be appreciated.

EDIT: Additional photos

Response on first submit

enter image description here

Response on second submit

enter image description here

Svedr
  • 589
  • 2
  • 6
  • 21
  • Why do you need the `name=action` input element if you are not using it? – Mikey Feb 14 '17 at 17:08
  • @Mikey i think he uses it on the backend – Dmytro Grynets Feb 14 '17 at 17:10
  • please post here the resulting html element when you visit the page, some content should appear in place of "<%=Inquiry.CREATE_ACTION_DESCRIPTION_DATA%>" – raythurnevoid Feb 14 '17 at 17:13
  • It's `create_description_data` @Lemmy4555 – Svedr Feb 14 '17 at 17:16
  • ok, i'm start thinking that you might have two onSubmit event attached to the form ot something with your jsp expression in some cases, could you check if the first time you click the submit button you pass through your code snippet? add a breakpoint to this line: `$form.submit(function (ev) {` And place here the content of formUrl variable please... I would suggest you to try to unbind with `$form.off()` right before bind the submit event – raythurnevoid Feb 14 '17 at 17:34

1 Answers1

-1

it would be great to see some jsp code, but now my guess is that if #descriptionData is actual from, then you'd better be using just $form.serialize() to send data

Dmytro Grynets
  • 923
  • 11
  • 29