Alchemy via JS
Using the Alchemy API via JS
by Eve Mwangi
HTML
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.cs"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-md-12 card">
<label>Paste your URL here</label>
<textarea class="form-control" rows="2"></textarea><br>
<center><button class="btn btn-primary">Submit</button></center>
</div>
</div>
<hr>
<div class="row">
<div class="col-md-6 card entity">
<h4>Entities</h4>
</div>
<div class="col-md-6 card sentiment">
<h4>Sentiment</h4>
</div>
</div>
</div>
CSS
body {padding-top:20px;}
.card {padding:20px;}
.entity {border-right:1px solid #ccc;}
h4 { border-bottom:2px solid #888;}
JavaScript
key = 'b66585d88e1c9cbb09218239e8b16ca03e17b567'
sentiment_api = "https://gateway-a.watsonplatform.net/calls/url/URLGetTextSentiment?apikey=" + key
entities_api = 'https://gateway-a.watsonplatform.net/calls/url/URLGetRankedNamedEntities?apikey=' + key
$('#submit').click(function() {
$.ajax({
method: "POST",
url: sentiment_api,
data: $('#form').serialize(),
contentType: 'application/x-www-form-urlencoded',
success: function(msg) {
// Write your code here
}
});
$.ajax({
method: "POST",
url: entities_api,
data: $('#form').serialize(),
contentType: 'application/x-www-form-urlencoded',
success: function(msg) {
// Write your code here
}
});
});