开发者

Ajax JQuery Issues in MVC 3

I am using https://github.com/Haacked/CodeHaacks to access my MVC actions.

I've tried the sample local and it works fine.

However, when I put it in my code it gives the following error...

开发者_Go百科

"Error: $mvc.ManageBanking.AddBank({Name: name}).done is not a function"

My code

    $(document).ready(function(){
        $('#NewBankButton').click(function () {
            var name = $('#txtBankName').val();

            $mvc.ManageBanking.AddBank({ Name: name }).done(function (data) {
                alert('done');
            });
        });
    });

Ajax Script

if (typeof $mvc === 'undefined') {
  $mvc = {};
}
$mvc.ManageBanking = [];
$.each(["AddBank","AddBankAccount"], function(action) {
 var action = this;
 $mvc.ManageBanking[this] = function(obj) {
   return $.ajax({
     cache: false,
     dataType: 'json',
     type: 'POST',
     headers: {'x-mvc-action': action},
     data: JSON.stringify(obj),
     contentType: 'application/json; charset=utf-8',
     url: '/json/managebanking?invoke&action=' + action
   });
 };
});

I was thinking it was my other script causing issues with it, but dont see anything that is messing with it... the method works because in my ManageBankingController, it steps through if I debug, but it doesnt go to the done event..

I was thinking "done" was wrong, but "success" doesnt work either..


if (typeof $mvc === 'undefined') {
  $mvc = {};
}
$mvc.ManageBanking = {};
$.each(["AddBank","AddBankAccount"], function(index, action) {
 $mvc.ManageBanking[ action ] = function(obj) {
   return $.ajax({
     cache: false,
     dataType: 'json',
     type: 'POST',
     headers: {'x-mvc-action': action},
     data: JSON.stringify(obj),
     contentType: 'application/json; charset=utf-8',
     url: '/json/managebanking?invoke&action=' + action
   });
 };
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜