Skip to content

Commit 4d1c088

Browse files
author
Emmanouil Konstantinidis
committed
Clean Up Response before new request
1 parent 267c0ba commit 4d1c088

File tree

1 file changed

+18
-6
lines changed
  • rest_framework_docs/static/rest_framework_docs/js

1 file changed

+18
-6
lines changed

rest_framework_docs/static/rest_framework_docs/js/index.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ var jsonPP = {
2222

2323
$( document ).ready(function() {
2424

25-
var setResponse = function (method, response) {
26-
if (!response.status) {
27-
return $('#responseData').html(jsonPP.prettyPrint(response));
28-
}
25+
var cleanResponse = function () {
26+
27+
$('#responseStatusCode').removeClass(function (index, css) {
28+
return (css.match (/(^|\s)label-\S+/g) || []).join(' ');
29+
});
30+
$('#responseStatusText').text( '' );
31+
$('#responseData').html( '' );
32+
};
2933

34+
var setResponse = function (response) {
3035
// Status Code
3136
var statusCodeFirstChar = String(response.status).charAt(0);
3237
var statusCodeClass;
@@ -70,6 +75,9 @@ $( document ).ready(function() {
7075
};
7176

7277
var makeRequest = function () {
78+
// Clean the response
79+
cleanResponse();
80+
7381
var url = $('#requestForm #urlInput').val();
7482
var method = $("#methods").find( ".active" ).text();
7583
var data = getFormData();
@@ -78,8 +86,12 @@ $( document ).ready(function() {
7886
method: method,
7987
context: document.body,
8088
data: data
81-
}).always(function(response) {
82-
setResponse(method, response);
89+
}).always(function(data, textStatus, jqXHR) {
90+
91+
if (textStatus != 'success') {
92+
jqXHR = data;
93+
}
94+
setResponse(jqXHR);
8395
});
8496
};
8597

0 commit comments

Comments
 (0)