0

Im trying to create an R-API using Plumber which accepts two arguments and returns a list object. The GET Call is happening using a JQuery Client but however the data is not getting displayed on the webpage . Tested the same API with Postman and the API works like charm . The return object is a NULL and there is also an error message in R ERROR: [on_request_read] connection reset by peer everytime I click the button on webpage . Any help to solve this is much appreciated.

#* @post /predict
predict2 <- function(a,b){
object = list(status = "SUCCESS", code = "200",output = list(studentid =     "1001", name = "Kevin"))
return(object)
  }

Jquery:

$(function() {
var submit_form = function(e) {
  $.getJSON('http://127.0.0.1:8000' + '/predict', {
    a: $('input[name="a"]').val(),
    b: $('input[name="b"]').val()
  }, function(data) {
    console.log(data)
    $('#result').text(data.result);
    $('input[name=a]').focus().select();
  });
  return false;
};

$('a#calculate').bind('click', submit_form);    
$('input[type=text]').bind('keydown', function(e) {
  if (e.keyCode == 13) {
    submit_form(e);
  }
});

$('input[name=a]').focus();
  });

Jil Jung Juk
  • 690
  • 2
  • 9
  • 21

1 Answers1

1

It looks like jQuery.getJSON issues a GET request, not a POST. Can you try $.post( or support @get requests in your plumber app?

Jeff Allen
  • 17,277
  • 8
  • 49
  • 70