How can we help?

Extract data from AJAX requests

You are here:

Quite often you need to make custom AJAX calls, extract data from them, and potentially validate the response. With Trudon you can use a custom function to achieve this. Check the following example that retrieves the project object for a given projectId.

function trudonJSStep(element, callbacks, builtinVars, customVars)
{
  // variables definition
  var projectId = customVars.projectId;
  
  var req = new XMLHttpRequest();

  req.addEventListener("load", function () {
      customVars.projectBody = this.responseText;
      callbacks.pass("Successful response");
      callbacks.done();
  });

  req.addEventListener("error", function (error) {
    callbacks.fail(error);
    callbacks.done();
  })

  req.open("GET", "https://jira.com/api/v2/projects/" + projectId);
  req.send();
}
Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Need help?