Created
December 17, 2014 02:27
-
-
Save nozzlegear/346d6427bac03bc66cb4 to your computer and use it in GitHub Desktop.
An example for using $.postJson with an ASP.NET AntiForgeryToken
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
| 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