0

I want to put this HTML form in an AJAX request and then save the response in a var. I've tried to intercept the submit and made an AJAX request an already asked this in other topics. I'm just looking for some explanation of how I can put all the 'important' code in mine AJAX request (like the grand_type etc.)

<!--   form for authentication   -->
    <form id="auth-form" action="https://rsgdeborgen.zportal.nl/api/v3/oauth/token" method="post">
    <!--   hidden post data      -->
    <input id="hidden-input" type="hidden" name="grant_type" value="authorization_code"/>
    <!--    user inputfield || user input = 12 number long authorization code from: https://rsgdeborgen.zportal.nl -->
    <input id="user-auth-input" name="code" type="text" placeholder="Koppelcode" minlength=12 maxlength=15 required autofocus/>
    <!--    post button    -->
    <button id="post-button" value="inloggen">inloggen</button>

This is an example of how figured my AJAX :

var body = {
    grant_type: 'authorization-code';
    authorization-code: document.getElementById("user-auth-input");
};

$.ajax({
    url: 'https://rsgeborgen.zportal.nl/api/v3/oauth/token',
    type: 'POST',
    dataType: 'json',
    contentType: 'text',
    data: body,
    complete: function(result) {
        //called when complete
        alert(result);
    },

    success: function(result) {
        //called when successful
        alert(result);
    },

    error: function(result) {
        //called when there is an error
        alert(result);
    },
});
Ullas Hunka
  • 1,939
  • 1
  • 12
  • 26
Aydin
  • 23
  • 7

0 Answers0