Discussions

Ask a Question
Back to All

How can I handle an "model_form" AJAX response?

(edited)

The guide Create a contact form briefly mentions that you can use the JSON API by adding json: true to the options. It gives an example response, but not much more than that.

In my option the guide is missing some key information. It doesn't tell me if I am responsible for making the request via JavaScript or if the Rails or LocomotiveCMS is doing this for me. If the latter is the case it should also describe how to handle the response. Eg. What event should callbacks be attached to?

I'd like to submit some data via an AJAX request but am currently unsure how to do this. I'd like to know the two things mentioned above.

  1. Must I initiate the AJAX request myself or is this done by the framework/CMS?
  2. If I don't have to initiate the request, how do I attach a callback to handle the response?