如何是人用搬运AJAX职位,以ActionMethods [ValidateAntiForgeryToken] [英] How are people handling AJAX posts to ActionMethods using [ValidateAntiForgeryToken]
本文介绍了如何是人用搬运AJAX职位,以ActionMethods [ValidateAntiForgeryToken]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
眼看使用AJAX和的 ValidateAntiForgeryTokenAttribute
是寻找的Request.Form令牌,如何人打交道这个问题。
Seeing that the __RequestVerificationToken is not sent when using AJAX and ValidateAntiForgeryTokenAttribute
is looking for the token in Request.Form, how are people dealing with this problem.
我落得这样做。
$("#regmember-form").submit(function (e) {
e.preventDefault();
var token = $('[name="__RequestVerificationToken"]').val();
alert($(this).attr('action'));
$.ajax({
url: $(this).attr('action'),
type: $(this).attr('method'),
data: { __RequestVerificationToken: token }
});
return false;
});
非常相似的<一个href=\"http://stackoverflow.com/questions/7264904/how-are-people-handling-ajax-posts-to-actionmethods-using-validateantiforgerytok/7264919#7264919\">accepted回答。
推荐答案
我抢输入关闭的页面,并将其发送回来的表单提交。这假定您将其包含在首位的页面上。
I grab the input off the page and send it back with the form post. This assumes that you include it on the page in the first place.
$('#somebutton').click( function() {
var data = $('[name="__RequestVerificationToken"]').serialize();
$.post('/foo/bar', data, function(result) {
// ...
});
});
这篇关于如何是人用搬运AJAX职位,以ActionMethods [ValidateAntiForgeryToken]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文