Alchemy via JS
Using the Alchemy API via JS
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-12 card">
<form id="form" method="post">
<label id="lbl">Paste your url here:</label>
<textarea id="textarea" class="form-control" rows="2" name="url"></textarea>
<br>
</form>
<center>
<button class="btn btn-primary" id="btn">Submit</button>
</center>
</div>
<hr>
<div class="row">
<div class="col-md-6 card sentiment">
<h4>Sentiment</h4>
<div id="sentiment-results"></div>
</div>
<div class="col-md-6 card entity">
<h4>Entities</h4>
<div id="entities-results"></div>
</div>
</div>
</div>
CSS
body {
padding-top: 20px;
}
#entities-results {
height: 100%;
}
.card {
padding: 20px;
}
.entity {
border-right: 1px solid #ccc;
}
h4 {
border-bottom: 2px solid #888;
}
#sentiment-results {
height: 100%;
}
JavaScript
//Your workspace
key = '51e2eb05801719c0c12dd695520bbd2811c7781f' // Enter AlchemyAPI key here
sentiment_api = 'https://gateway-a.watsonplatform.net/calls/url/URLGetTextSentiment?outputMode=json&apikey=' + key
entities_api = 'https://gateway-a.watsonplatform.net/calls/url/URLGetRankedNamedEntities?outputMode=json&sentiment=1&apikey=' + key
outputMode = '&outputMode=json' // We want the response in JSON
$('#btn').click(function() {
$.ajax({
method: "POST",
url: sentiment_api + outputMode,
data: $('#form').serialize(),
contentType: 'application/x-www-form-urlencoded',
success: function(msg) {
// Write your response handling code here
}
});
$.ajax({
method: "POST",
url: entities_api + outputMode,
data: $('#form').serialize(),
contentType: 'application/x-www-form-urlencoded',
success: function(msg) {
// Write your response handling code here
}
});
$.ajax({
method: "POST",
url: sentiment_api + outputMode,
data: $('#form').serialize(),
contentType: 'application/x-www-form-urlencoded',
success: function(msg) {
// Write your response handling code here
}
});
});