Skip to content Skip to sidebar Skip to footer

Using Rest Api And Send Post Request

POST localhost:5000/registrar { 'enrollId': 'jim', 'enrollSecret': '6avZQLwcUe9b' } How do I use this in a javascript file? Do I use JSON or JQuery? And how do I invoke the r

Solution 1:

Use jquery for this:

<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>

And call function

$(document).ready(function(){

    $.post('localhost:5000/registrar', {
      "enrollId": "jim",
      "enrollSecret": "6avZQLwcUe9b"
    }, function(serverResponse){

    //do what you want with server response

    })

})

Same without shorthand to handle errors:

$.ajax({
  type: "POST",
  url: 'localhost:5000/registrar',
  data: {
      "enrollId": "jim",
      "enrollSecret": "6avZQLwcUe9b"
    },
  success: function(){$('#register').html('<h1>Login successfull</h1>');},
  error: function(){$('#register').html('<h1>Login error</h1>');},
  dataType: dataType
});

Post a Comment for "Using Rest Api And Send Post Request"