title: Is it possible to use GET & POST inside one $.ajax for login?
body: <p>Good day,</p>
  <p>We are building a project that uses WordPress for the marketing(normal pages, blogs, etc) and angular for the more functional side of this project. My current issue is we use the wordpress side for registration, subscribing to newsletter, and logging in. Newsletter and registration is now okay but I have a problem with the login. I'm using a custom bootstrap form, and use ajax. I'm given an api to get the login token first, then include that token in post for logging in.</p>
  <p>This is currently what I got in my scripts.js:</p>
  <pre><code>$('#login-button').click(function(event) {
    event.preventDefault();
  
    // extracting the token
    $.get(&quot;https://sample-dummy-url/Account/Loginwp&quot;, function(data, status){
      // setting the token to loginToken variable to include in logging in
      loginToken = $(data).find(&quot;input[name='__RequestVerificationToken']&quot;).val();
      
      // checking if token is extracted
      console.log(loginToken);
    });
  
    // I know this will be empty outside of the function of getting the token, but this is my current idea
    console.log(loginToken);
  
    // setting the variable to pass for logging in
    let login = { 
      Username: $('#loginUsername').val(),
      Password: $('#loginPassword').val(),
      button: 'login',
      // this is where I supposedly assign the extracted token but I know this is empty
      __RequestVerificationToken: loginToken,
      RememberLogin: $('#loginRememberMe').is(&quot;:checked&quot;),
    }
  
    // ajax for logging in
    $.ajax({
        url: 'https://sample-dummy-url/Account/Login',
        headers: {
          'Access-Control-Allow-Origin': '*',
          'Accept': 'application/json',
          'Content-Type': 'application/json; charset=UTF-8'
        },
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(login),
        success: function(msg, textStatus, jqXHR) {
          console.log(&quot;logged in&quot;);
        },
        error: function(msg, textStatus, jqXHR) {
          console.log(msg);
          console.log(textStatus);
          console.log(jqXHR);
        },         
    });
  });
  </code></pre>
  <p>My idea was only to invoke the getting of token when login button is clicked, then extract the token to a variable so I could include it in the login object so that when I use another ajax to post for login. I know this might be not the best/ideal/practical implementation, but I am truly open for suggestions &amp; enlightenment of the proper way of doing it.</p>
  <p>Thank you for any help.</p>