0

I have an AJAX call on MVC3 it looks like this

save: function () {
        $.ajax({
            url: "@Url.Action("Save")",
            type:"post",
            data: ko.toJSON(this),
            contentType:"application/json",
            success: function(result){alert(result.message)}
        });
    }

The trouble is the line

success: function(result){alert(result.message)}

I want to pass all the messing things in a HtmlHelper, however, the success line prevents me from doing so, is there a way I can specify a function for that line

success: doSomeStuff(result)

and

function doSomeStuff(result){alert(result.message)}

Thanks in advance

1 Answers1

2

Simply pass the function name to the success: method and it will pass the data onwards, as such:

save: function () {
        $.ajax({
            url: "@Url.Action("Save")",
            type:"post",
            data: ko.toJSON(this),
            contentType:"application/json",
            success: doSomeStuff
        });
    }
Niklas
  • 29,752
  • 5
  • 50
  • 71