Skip to content

Instantly share code, notes, and snippets.

@dpawluk
Last active November 29, 2017 19:30
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 dpawluk/c79b3701e844ca118e1f433d950ea4cd to your computer and use it in GitHub Desktop.
Save dpawluk/c79b3701e844ca118e1f433d950ea4cd to your computer and use it in GitHub Desktop.
This implies a button with id="testsub" exists to actually test running this code. It uses the ZD Help Center session to create a dummy request when the button is clicked.
$(document).ready(function() {
$('#testsub').click(function(){
$.ajax('/api/v2/users/me.json').then(function(udata){
var csrf_auth = udata.user.authenticity_token;
console.log(csrf_auth);
$.ajax({
url: "/api/v2/requests.json",
contentType: "application/json",
type: "POST",
data: JSON.stringify({
"request":{
"comment":{
"body":"comment body!"
}
}
}),
headers: {
"X-CSRF-Token": csrf_auth
}
}).done(function(data){console.log(data)});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment