How can I call my sankey_continue() function after the .each is done? I had a look at promise but don't know how to implement it or if there is a different solution. Any help or suggestions is appreciated.
function pattern() {
                $.ajax({
                    type: "POST",
                    url: "Dashboard.aspx/patterns",
                    data: '',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        if (data.d != "0") {
                            //thePatterns = [];
                            var obj = $.parseJSON(data.d);
                            $.each(obj, function (i, v) {
                                svg.append('defs').append('pattern')
                                     .attr('id', v.id_pattern)
                                     .attr('patternUnits', 'userSpaceOnUse')
                                     .attr('width', eval(v.w1))
                                     .attr('height', eval(v.h1))
                                     .append("svg:image")
                                     .attr("xlink:href", v.data_pattern)
                                     .attr("width", eval(v.w1))
                                     .attr("height", eval(v.h1))
                                     .attr("x", 0)
                                     .attr("y", 0);
                            });
                            sankey_continue();
                        }
                    } //end success
                }); //end ajax call
            }
 
     
    