我有以下问题,下面的MVC项目的细节。
当我试图使用jquery ajax请求与加载面板,如旋转gif(甚至文本),我得到错误,从提琴家观察到
The required anti-forgery form field “__RequestVerificationToken” is not present.
如果我发表评论
[ValidateAntiForgeryToken]属性在POST操作方法和使用加载面板它是正常工作。我想知道为什么我得到这个错误。
我甚至使用序列化的查询字符串
__RequestVerificationToken= $('input[name="__RequestVerificationToken"').val()
仍然我得到错误
The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster,ensure that all machines are running the same version of ASP.NET Web Pages and that the configuration specifies explicit encryption and validation keys.
AutoGenerate不能在群集中使用
我应该使用什么?
这里更新了问题码
var token = $('input[name="__RequestVerificationToken"]').val();
$('#submitaddress').click(function subaddr(event) {
event.preventDefault();
event.stopPropagation();
//$('#addAddress').html(' Sending...');
// $('#addAddress').blur();
// $(this).bl
if ($('#Jobid').val()!="") {
$('#TransportJobId').val(parseInt($('#Jobid').val()));
$.ajax(
{
url: '/TransportJobAddress/create',type: 'POST',data: "__RequestVerificationToken=" + token + "" + $('form[action="/TransportJobAddress/Create"]').serialize(),success: function poste(data,textStatus,jqXHR) { $('#addAddress').html(data); return false; },error: function err(jqXHR,errorThrown) { alert('error at address :' + errorThrown); }
});
}
else {
var transportid = 2;
$.ajax({
url: '/TransportJob/create',data: "__RequestVerificationToken=" + token + "" + $('form[action="/TransportJob/Create"]').serialize(),success: function sfn(data,jqXHR) {
transportid = parseInt(data);
$('#Jobid').val(data);
// alert('inserted id :' + data);
$('#TransportJobId').val((transportid));
$.ajax(
{
url: '/TransportJobAddress/create',//beforeSend: function myintserver(xhr){
// $('#addAddress').html('
//},jqXHR) {
$('#addAddress').html(data);
},errorThrown) {
alert('error at address :' + errorThrown);
}
});
},error: function myfunction(jqXHR,errorThrown) {
alert("error at transport :" + jqXHR.textStatus);
},complete: function completefunc() {
// alert('ajax completed all requests');
return false;
}
});
}
});
表单标签
运输工具
表单标签2在同一页面上