Alvin Alvin - 4 months ago 25
Javascript Question

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 request function in .html?

Answer

Use jquery for this:

<script src="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

    })

})
Comments