Last active
November 29, 2017 19:30
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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