0

I have a HTML submit form with Name, Email, Phone, Password inputs. After clicking "Submit" button I send all the data to API through jQuery script:

function login() {
  var request = new XMLHttpRequest();
  request.open('POST', 'https://ensyu6r51m3oldb.m.pipedream.net');
  request.setRequestHeader('Content-Type', 'application/json');
  request.setRequestHeader('Accept', '*/*');

  request.onreadystatechange = function() {
    if (this.readyState === 4) {
      console.log('Status:', this.status);
      console.log('Headers:', this.getAllResponseHeaders());
      console.log('Body:', this.responseText);
    }
  };
  
  var arguments = $('#h14kLToIyLIMrHQDo37BZUtKoTg6bMlH').serializeArray().reduce(function(obj, item) {
    obj[item.name] = item.value;
    return obj;
  }, {});
  
  var body = { arguments };
  request.send(JSON.stringify(body));
}

Now comes the part where I need help with - I get an response from API provider with the URL which I should redirect user for autologin, but I have no clue how to take that URL and redirect to it.

Here is the example of API response:

{
    "status": "something"
    "url": "https.." // redirect to that
    "object_id": xxx // customer ID
}  

Maybe someone could help me in tweaking script so the user would be redirected for autologin to the URL which should be taken from API response?

Thanks a lot for your help!

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

1 Answers1

0

You can change the location.href on the window object to the url you received in response. The code for this is

window.location.href = JSON.parse(this.responseText).url;