Last active
December 12, 2015 00:38
-
-
Save JogoShugh/4684780 to your computer and use it in GitHub Desktop.
How to use jQuery to GET a User Story
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="error"> | |
<h1>Error During AJAX Call:</h1> | |
<br /> | |
<hr /> | |
<br /> | |
<p id="errorMessage"> | |
</p> | |
</div> | |
<div id="success"> | |
<h1>Now, that's <b>beautiful JSON</b>:</h1> | |
<br /> | |
<pre id="output"></pre> | |
<br /> | |
<a id="link"></a> | |
<br/> | |
<br/> | |
Right click and select <code>Open link in new tab</code> to play with this request some more. | |
</p> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = "http://eval.versionone.net/platformtest/rest-1.v1/Data/Story/1154?sel=Name,Description,Estimate"; | |
var headers = { Authorization: "Basic " + btoa("admin:admin"), Accept: "haljson" }; | |
var settings = { url: url, headers: headers, dataType: "json" }; | |
$.ajax(settings).done(function(data) { | |
beautifulJson = JSON.stringify(data, null, 4); | |
link = settings.url + "&acceptFormat=haljson"; | |
$("#link").attr("href", link).text(link); | |
$("#error").hide(); | |
$("#output").text(beautifulJson); | |
$("#success").css("visibility", "visible").fadeIn(); | |
}).fail(function(jqXHR) { | |
$("#success").hide(); | |
$("#errorMessage").html(jqXHR.responseText); | |
$("#error").css("visibility", "visible").fadeIn(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 10px | |
} | |
#error { | |
background: lightyellow; | |
border: 2px solid firebrick; | |
padding: 10px; | |
visibility: hidden; | |
} | |
#success { | |
background: whitesmoke; | |
border: 2px solid firebrick; | |
padding: 10px; | |
visibility: hidden; | |
} | |
#output, #errorMessage { | |
font-size: 80%; | |
border: 1px solid darkgray; | |
background: linen; | |
padding: 6px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment