Mark Mark - 4 months ago 12
jQuery Question

How do I pass a parameter to a Javascript .done function from a .success function?

How do I pass data from a .success function to a done function?

$.ajax({
url: "/Bifrost/SetLanguagesTiefling",
success: function () {
var count = 4;
},
error: function () { alert("SetLanguagesTiefling"); },
type: 'POST'
})
.done(function (count) {
SaveLanguages(count);
})

Answer

It works if I declare count as a global variable and then assign values to count within local scope.

var count;
$.ajax({
    url: "/Bifrost/SetLanguagesTiefling",
    success: function () {
        count = 4;
    },
    error: function () { alert("SetLanguagesTiefling"); },
    type: 'POST'
})
.done(function () {
    SaveLanguages(count);
})
Comments