2012-05-15 60 views
0

这是我的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.'); 
         } 
        }); 
       } 
      }); 
+0

删除数据:{}或添加一个时间戳,如数据:{_t:new Date()。getTime()},然后重试。尝试删除授权过滤器,并查看是否可能请求未经过身份验证。 –

+0

此外,返回这个'{返回Json(“完成”,JsonRequestBehavior.AllowGet)}'添加'JsonRequestBehavior.AllowGet'可能会有所帮助。查看文档:http://msdn.microsoft.com/en-us/library/system.web.mvc.jsonrequestbehavior.aspx –

回答

3

我不是100%肯定,但你不应该控制器动作处理程序是public

+0

:D:D:D你说得对。我已经非常累了2个小时,试图找到问题和...:D再次感谢 –

+0

+1如此明显 - 当你看到它!不错的地方 –