Created
December 17, 2014 02:20
-
-
Save nozzlegear/4abc71e8f9731f37c68e to your computer and use it in GitHub Desktop.
Extending jQuery to send json in a post with an ASP.NET AntiForgeryToken header
This file contains 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
jQuery.postJSON = function (url, data, success, antiForgeryToken, dataType) { | |
if (dataType === void 0) { dataType = "json"; } | |
if (typeof (data) === "object") { data = JSON.stringify(data);} | |
var ajax = { | |
url: url, | |
type: "POST", | |
contentType: "application/json; charset=utf-8", | |
dataType: dataType, | |
data: data, | |
success: success | |
}; | |
if (antiForgeryToken) { | |
ajax.headers = { | |
"__RequestVerificationToken": antiForgeryToken | |
}; | |
}; | |
return jQuery.ajax(ajax); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment