Test Wit.ai api

by Ayan Dey

HTML

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<input id="input" placeholder="User says..">
<div id="result">
</div>

CSS

#input {
  width: 100%;
  height: 50px;
  font-size: 30px;
  padding: 10px;
  margin-bottom: 20px;
}

#result {
  width: 100%;
  min-height: 50px;
  height: auto;
  overflow-y: auto;
  background-color: lightgray;
  padding: 10px;
}

JavaScript

$('#input').keypress(function(e) {
  if (e.which == 13) {
    var query = $(this).val();
    makeRequest(query);
    return false;
  }
});

function makeRequest(query) {
  $.ajax({
    url: 'https://api.wit.ai/message',
    data: {
      'q': query,
      'access_token': 'KSNBPLG4JDFEFDAVNHJUWYZIRUUGUAGU'
    },
    dataType: 'jsonp',
    method: 'GET',
    success: function(response) {
      console.log("success!", response);
      $('#result').text(JSON.stringify(response));
    }
  });
}