Skip to content

Instantly share code, notes, and snippets.

@dminuoso
Forked from anonymous/some.js
Last active June 27, 2017 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/15ba3ebff7f9b92b0495fbd5ccf3790c to your computer and use it in GitHub Desktop.
Save dminuoso/15ba3ebff7f9b92b0495fbd5ccf3790c to your computer and use it in GitHub Desktop.
// Arrow function
$("#ajax-action2").click(() => {
const AUTH_TOKEN = $("meta[name=csrf-token]").attr("content");
// const
const request = $.ajax({
type: "PATCH",
url: "/home/no_js_view_action",
headers: {
'X_CSRF_TOKEN': AUTH_TOKEN,
},
dataType: "json",
data: {
some_data: {}
}, // trailing comma for your own sanity
});
/*
* 1. Use #id not .class to identify a single element.
* 2. Arrow functions.
* 3. Linus would be proud of this comment-style.
*/
request.done((msg) => $( "#response-div" ).html(msg.data));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment