Copy tanserver.js
into your project and include it.
Browser | Version |
---|---|
Chrome | 5+ |
Edge | 12+ |
Firefox | 11+ |
Safari | 5.1+ |
Chrome Android | 18+ |
Firefox Android | 14+ |
Safari iOS | 6+ |
<script src="./tanserver.js"></script>
<script defer>
/* Initialize connection information. */
var tan = new Tanserver("tanserver.org", 2579);
/* Get JSON string from the server. */
tan.getJSON('API', '{}', function(jsonData, err) {
if (err != null) {
alert(err); /* An error has occurred, notify the user of network failure. */
return;
}
/* Got a JSON string, parse it here. */
var json = JSON.parse(jsonData);
...
});
</script>
Declaration | getJSON(userApi: string, jsonString: string, completion(jsonData, err): function) |
---|---|
Description | Get JSON answer from the server. |
Param userApi |
API provided by the server. |
Param jsonString |
The JSON string that will be sent to the server. |
Param completion(jsonData, err) |
jsonData will contain JSON answer from tanserver. If an error occurs, err will not be null. |
-
The client is offline or the server is not started.
-
SSL handshake failed.
-
API does not exist.
-
jsonString
is an invalid JSON string.