$(document).ready(function() {
$.getJSON('/users', function(data) {
console.log(data);
});
$('.btn').click(function() {
var user = $('input[name="user"]').val();
var pass = $('input[name="pass"]').val();
$.post('/users', $('#myform').serialize())
.done(function(data) {
console.log(data);
});
});
});
This code will make a GET request to /users
endpoint when the page is loaded, and make a POST request to the same endpoint when the button with class btn
is clicked. It will serialize the data from the form with id myform
and log the response from the server to the console.
