javascript - JS function not sending a request -
this code should work i'm missing something, how can debug js code know where's problem? i'm sending user input (string) third party api, should expect json results in <p class="score">
nothing happens!
var myurl = 'https://apiv2.indico.io/sentiment'; var api_key = 'xxxxxxxxxxxxxxxxxxxxxxx'; function apirequest() { var mydata = document.getelementbyid('userinput').value; $.post( myurl, json.stringify({ 'api_key': api_key, 'data': mydata, }).then(function(sent) { var s = sent var obj = json.parse(s) $('.score').append(obj.results) });
html
<input placeholder="i love writing code!" id="userinput"> <button onclick="apirequest" id="submit">try it</button> <p class="score">score : </p>
the userinput
not passed javascript it's accessible via alert
Comments
Post a Comment