Skip to content

Commit

Permalink
Better handling of non-json ajax response.
Browse files Browse the repository at this point in the history
Hi there... great Project! 

If response is non-json, but for example xml... then the output is not readable. 

This commit fix this (its also dom-safe)
  • Loading branch information
phpsyscoder authored Jul 20, 2019
1 parent bfe86d9 commit 0af565c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions template/utils/send_sample_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ define([
jsonResponse = JSON.parse(jqXHR.responseText);
jsonResponse = JSON.stringify(jsonResponse, null, 4);
} catch (e) {
jsonResponse = data;
jsonResponse = jqXHR.responseText;
}
$root.find(".sample-request-response-json").html(jsonResponse);
$root.find(".sample-request-response-json").text(jsonResponse);
refreshScrollSpy();
};

Expand All @@ -125,18 +125,18 @@ define([
jsonResponse = JSON.parse(jqXHR.responseText);
jsonResponse = JSON.stringify(jsonResponse, null, 4);
} catch (e) {
jsonResponse = escape(jqXHR.responseText);
jsonResponse = jqXHR.responseText;
}

if (jsonResponse)
message += "<br>" + jsonResponse;
message += "\n" + jsonResponse;

// flicker on previous error to make clear that there is a new response
if($root.find(".sample-request-response").is(":visible"))
$root.find(".sample-request-response").fadeTo(1, 0.1);

$root.find(".sample-request-response").fadeTo(250, 1);
$root.find(".sample-request-response-json").html(message);
$root.find(".sample-request-response-json").text(message);
refreshScrollSpy();
};
}
Expand Down

0 comments on commit 0af565c

Please sign in to comment.