I want to use the ajax capability of not refreshing the page or rerouting the user to the registration page. The site has login / register dialogue modals. I have the login javascript ajax working perfectly using an ajax call to the login api and I want to integrate the registration form in the same way. I would like the registration to: 1. show in a modal - this works. 2. Submit javascript code works with preventDefault 3. response is failing. Ajax Post is returning '<' obviously this is returning some html. How do I know how to pass the data in the ajax call and what to expect as a response? ``` <style> .scroll { //background-color: #fed9ff; //width: 600px; height: 500px; overflow-x: hidden; overflow-y: auto; //text-align: center; //padding: 20px; } .close { margin: 10px 25px 0px; } #log-title { margin-left:25px; } </style> <a data-target="#register-modal" data-toggle="modal" class="" id="" href="#register-modal">Register / Create an Account </a> <div id="overlay_container"></div> <!-- Register to download button so stays on same page. --> <div id="register-modal" class="modal" tabindex="-1" role="dialog" aria-hidden="true"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> <h3 id="log-title">Please register:</h3> <div class="modal-dialog"> <div class="modal-content scroll"> <?php $register_form = \Drupal::service('entity.form_builder')->getForm(\Drupal\user\Entity\User::create([]), 'register', []); // Load the service renderer $render = Drupal::service('renderer'); $rform = $render->renderPlain($register_form); echo $rform; ?> </div> <!-- Register modal content end--> </div><!-- Register modal-dialog end --> </div><!-- Register modal end --> <script> var registerForm = document.getElementById('user-register-form'); if (registerForm ) { // capture registration submit, prevent from submission and use ajax to get response registerForm.onsubmit = async (e) => { e.preventDefault(); // callRegCaptcha(); elms =document.getElementById("user-register-form").elements; var url = "https://website/user/register"; fetch(url, { method: 'POST', body: elms }) .then(response=>response.json()) .then(json => { console.log(json); }); } } </script> ``` Everything is working except the response. I cant find anywhere what to expect as a response. Or if Im binding the data of elms correctly. Can anyone help me in this area? The login required a csrfToken to be passed along with headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrfToken }, and "?_format=json" appended to the url but for the registration values I am running blindly. Does anyone have any information on what to pass? The response I get is the html page.