这是我的jQuery使用JSONasp.net MVC 3 JSON不起作用
$('#btnVerificationOk').click(function() {
var verId = $('#trans_verification_id').val();
var verCode = $('#trans_verification_code').val();
$.ajax({
url: '/Profile/CompleteTransactions',
type: 'POST',
data: { },
dataType: 'json',
success: function (result) {
alert(result);
},
error: function() {
alert('ERROR ERROR !!!!!!!!!!!!');
}
});
});
和我的C#方法:
[Authorize]
[HttpPost]
private JsonResult CompleteTransactions()
{
return Json("Done");
}
它总是提示“error错误!!!!!!! !!!!!”我试图调试,但CompleteTransactions方法不点火
这是我的第二个JSON是波纹管和做工不错
$('#btnTransfareOk').click(function() {
var userName = $('#transfare_username').val();
var amount = $('#transfare_amount').val();
if (userName == '' || amount == '') {
$('#transfare_error_list').html('Please fill boxes.');
} else {
$.ajax({
url: '/Profile/TranfareMoney',
type: 'POST',
data: { ToUsername: userName, Amount: amount },
dataType: 'json',
success: function (result) {
$('#transfare_error_list').html(result.text);
$('#trans_verification_id').val(result.id);
$('#transfare_username').val("");
$('#transfare_amount').val("");
},
error: function() {
$('#transfare_error_list').html('Oops... Error.');
}
});
}
});
删除数据:{}或添加一个时间戳,如数据:{_t:new Date()。getTime()},然后重试。尝试删除授权过滤器,并查看是否可能请求未经过身份验证。 –
此外,返回这个'{返回Json(“完成”,JsonRequestBehavior.AllowGet)}'添加'JsonRequestBehavior.AllowGet'可能会有所帮助。查看文档:http://msdn.microsoft.com/en-us/library/system.web.mvc.jsonrequestbehavior.aspx –