Skip to content

Testing Annotopia with a JavaScript cilent

Paolo Ciccarese edited this page Mar 25, 2014 · 3 revisions

This is using jQuery AJAX features to connect to the Annotopia server. Annotopia must enable CORS for these tests to work.

<html>
	<head>
		<title>Annotopia test</title>
		<script src="js/jquery-2.1.0.min.js"></script>
		<script>
			$(document).ready(function() {
				try {
					$.ajax({
						headers: {
							"Content-Type": "application/json; charset=utf-8"
						}
					})
					
					var dataToSend = {
						apiKey: 'testkey'
					};
					
					var savingRequest = $.ajax({
						url: "http://localhost:8080/s/annotation",
						type: "GET",
						dataType: "json",
						data: dataToSend 
					}).done(function(data) {
						alert("done");
						console.log(data);
					}).fail(function(what) { 
						alert("error "); 
						console.log(what);
					}).always(function() { 
						// Do nothing
					});
					
					var savingRequest = $.ajax({
						url: "http://localhost:8080/s/annotationset",
						type: "GET",
						dataType: "json",
						data: dataToSend
					}).done(function(data) {
						alert("done");
						console.log(data);
					}).fail(function(what) { 
						alert("error "); 
						console.log(what);
					}).always(function() { 
						// Do nothing
					});
				} catch(e) {
					alert(e);
				}
			});
		</script>
	</head>
	<body>
		
	</body>
</html>