Skip to content

Commit

Permalink
#29 POST parsed data to server
Browse files Browse the repository at this point in the history
  • Loading branch information
prayerslayer committed Dec 15, 2016
1 parent eb5f5aa commit 0a4108c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion zign/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@
</style>
<script>
(function extractFragmentQueryString() {{
function post(url, body, successCb, errorCb) {{
var success = successCb || noop;
var error = errorCb || noop;
var req = new XMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/json");
req.onreadystatechange = function() {{
if (req.readyState === XMLHttpRequest.DONE) {{
if (req.status >= 200 && req.status < 300) {{
success(req);
}} else {{
error(req);
}}
}}
}}
req.send(JSON.stringify(body));
}}
function displayError(message) {{
var errorElement = document.getElementById("error");
errorElement.textContent = message || "Unknown error";
Expand All @@ -69,7 +87,9 @@
var query = window.location.hash.substring(1);
var params = parseQueryString(query);
if (params.access_token) {{
window.location.href = "http://localhost:{port}/?" + query;
post("http://localhost:{port}", params, null, function error() {{
displayError("Error: Could not POST to server.")
}});
}} else {{
displayError("Error: No access_token in URL.")
}}
Expand Down

0 comments on commit 0a4108c

Please sign in to comment.