"Jokes API": creating a joke (with jwt-auth)





// Javascript code to send token to API:
$(function(){
    // see http://malsup.com/jquery/form/ for info about ajaxForm()
    $("#apiForm").ajaxForm({
        beforeSend: function(request){
            // set token in header
            request.setRequestHeader('Authorization', 'Bearer ' + localStorage.token);
        },
        dataType:  'json',
        success: function(data) {
            // Decode and show the returned data nicely. See http://t4t5.github.io/sweetalert/ for info of swal()
            swal("API response:\n"+JSON.stringify(data));
        },
        error: function(data) {
            swal({ html:true, title:'Error', text:JSON.stringify(data)+"

When receiving eror 'token_not_provided', first run: 'Demo getting & storing token clientside'"}); //document.getElementById("body").innerHTML = JSON.stringify(data); } }); });

Contact

Location

Westerpark, Amsterdam, Netherlands

Send an e-mail