Skip to content

Instantly share code, notes, and snippets.

@flanker
Created May 9, 2017 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flanker/993d3ba3001f5ba03227cc47264b9719 to your computer and use it in GitHub Desktop.
Save flanker/993d3ba3001f5ba03227cc47264b9719 to your computer and use it in GitHub Desktop.
API Test example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>API Test</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
</head>
<body>
<script>
// 201 created
$.ajax({
type: 'POST',
url: 'https://im.jinshuju.com/api/v1/forms/$TOKEN',
contentType : 'application/json',
data: '{"field_1": "中文测试1"}',
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + $AUTH_CODE);
},
success: function () {
alert('OK');
}
});
// 201 created
$.ajax({
type: 'POST',
url: 'https://im.jinshuju.com/api/v1/forms/$TOKEN',
contentType : 'application/json',
data: JSON.stringify({"field_1": "中文测试2"}),
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + $AUTH_CODE);
},
success: function () {
alert('OK');
}
});
// 400 bad request
$.ajax({
type: 'POST',
url: 'https://im.jinshuju.com/api/v1/forms/$TOKEN',
contentType : 'application/json',
data: {"field_1": "中文测试2"},
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + $AUTH_CODE);
},
success: function () {
alert('OK');
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment