Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <body>
- </br>
- <div>
- <input id="button" type="button" value="Load Activity" onclick="loadActivity($('#activityId').val())"/>
- <input id="activityId" type="text" value="20202"/><input id="token" type="text" value=""/>
- </div>
- </br>
- <textarea rows="100" cols="200"></textarea>
- </body>
- <script>
- $(document).ready(function() {
- authenticate();
- });
- function authenticate() {
- //Authentication endpoint
- var url = "http://localhost/rest/security/user/";
- var authRequest = {};
- authRequest.username = 'atl@amp.org';
- authRequest.password = 'a9993e364706816aba3e25717850c26c9cd0d89d';
- authRequest.workspaceId = 117;
- var client = new XMLHttpRequest();
- client.open("POST", url, true);
- client.setRequestHeader("Content-Type", "application/json");
- client.setRequestHeader("Acept", "application/json");
- client.onload= function (e){
- if (client.status == 200) {
- $('#token').val(JSON.parse(client.responseText).token);
- } else{
- alert("The request did not succeed!\n\nThe response status was: " + client.status + " " + client.statusText + ".");
- alert("The error message was " + client.responseText );
- }
- };
- client.onerror = function (e) {
- console.error(xhr.statusText);
- };
- client.send(JSON.stringify(authRequest));
- }
- function loadActivity(activityId) {
- var url = "http://localhost:8080/rest/activity/projects/" + activityId;
- var client = new XMLHttpRequest();
- client.open("GET", url, true);
- client.setRequestHeader("Content-Type", "application/json");
- client.setRequestHeader("X-Auth-Token", $('#token').val());
- client.onload = function(e) {
- if (client.status == 200) {
- // we parse the response object in case we need to process it as a JavaScript object
- jsonobj = JSON.parse(client.responseText);
- $('textarea').text(JSON.stringify(jsonobj, null, '\t'));
- } else {
- //In case client.status is not 2xx then we need to properly handle errors.
- alert("The request did not succeed!\n\nThe response status was: " + client.status + " " + client.statusText + ".");
- }
- ;
- };
- client.send();
- }
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement