javascript - Passing a string value to JS funtion code on submit -


i'm sending user input (string) third party api, should expect json results in <p class="score"> nothing happens! userinput not passed javascript it's accessible via alert can please let me know if there's problem syntax?

var myurl = 'https://apiv2.coolcompany.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)     });
<input placeholder="i love writing code!" id="userinput">        <button onclick="apirequest()" id="submit">try it</button>    <p class="score">score : </p>

you're missing ) of post , } of apirequest function:

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)         }); } 

what code call then on result of json.stringify.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -