-
-
Save addoull/8ee90ae016e7fb90bd9430c269fd0acb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<!-- Required meta tags --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<!-- Bootstrap CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous"> | |
<title>XMRig API test</title> | |
</head> | |
<body> | |
<div class="container"> | |
<form style="margin-top: 12px"> | |
<div class="form-group"> | |
<label for="address">API address</label> | |
<input type="text" class="form-control" id="address" required placeholder="http://"> | |
</div> | |
<div class="form-group"> | |
<label for="token">Access Token</label> | |
<input type="password" class="form-control" id="token" placeholder="Optional"> | |
</div> | |
<button id="submit" type="submit" class="btn btn-primary">Get API data</button> | |
</form> | |
<pre id="result" style="margin-top: 12px; border: 1px solid rgba(0,0,0,.15); padding: 12px"></pre> | |
</div> | |
<!-- Optional JavaScript --> | |
<!-- jQuery first, then Popper.js, then Bootstrap JS --> | |
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script> | |
<script> | |
$(function() { | |
$('#address').val(localStorage.getItem('address')); | |
$('#token').val(localStorage.getItem('token')); | |
$('#submit').on('click', function(event) { | |
var address = $('#address').val(); | |
if (!address) { | |
return; | |
} | |
event.preventDefault(); | |
getData(address, $('#token').val()); | |
}); | |
function getData(address, token) { | |
var headers = {}; | |
if (token) { | |
headers.Authorization = 'Bearer ' + token | |
} | |
$.ajax({ | |
method: 'get', | |
url: address, | |
headers: headers | |
}) | |
.done(function(data, textStatus, jqXHR) { | |
$('#result').text(jqXHR.responseText); | |
localStorage.setItem('address', address); | |
localStorage.setItem('token', token); | |
}) | |
.fail(function(jqXHR, textStatus) { | |
$('#result').text('Failed to get data (' + jqXHR.status + ')'); | |
}); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment