Submit form with FormData in jQuery - without Ajax and without hidden fields

I have a function that does some custom work with the submit form, sends some data through Ajax, adds the returned data to a new FormData object, now I need to send the form conditionally (and not through Ajax) using this FormData. I understand that this can be achieved with hidden fields, but what if I don't want the returned data to be visible to someone who knows a bit of coding?

So, is it possible to submit a form using a special FormData in jQuery without hidden fields and Ajax?

+5
source share
2 answers

You can add your object to the form before submitting and delete it immediately afterwards.

$('#yourForm').submit(function() { $(this).append(yourCustomObject) $(this).submit(); $(yourCustomObject).remove(); }); 
+1
source

Currently, since you cannot raise a submit event from a FormData object, follow these steps:

  • intercept the original send event preventing default send behavior
  • copy the original form to a new instance of FormData (everything will copy)
  • use jquery ajax or native XHR to invoke the server action Note that the effect of invoking ajax has the same meaning for invoking ajax / xhr using the correct configuration.
0
source

All Articles