Skip to content

Instantly share code, notes, and snippets.

@nozzlegear
Created December 17, 2014 02:27
Show Gist options
  • Select an option

  • Save nozzlegear/346d6427bac03bc66cb4 to your computer and use it in GitHub Desktop.

Select an option

Save nozzlegear/346d6427bac03bc66cb4 to your computer and use it in GitHub Desktop.
An example for using $.postJson with an ASP.NET AntiForgeryToken
function myFunction () {
//Grab antiForgeryToken. (Don't forget to add @Html.AntiForgeryToken() to your view or this will be empty)
var antiForgeryToken = $("input[name=__RequestVerificationToken]").val();
//Prepare parameters
var params = {
FirstName: "Joshua",
LastName: "Harms"
};
//Send parameters as JSON, including the AntiForgeryToken to be validated by our ASP.NET backend
$.postJson("/somepath/dosomething", params, function success (data) { console.log("Success!"); }, antiForgeryToken);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment