Call another method onSuccess event of an Ajax call

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

Answers:

Answer

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
        });
    }

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.