2

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
            }
Rob
  • 1,226
  • 3
  • 23
  • 41

1 Answers1

0

JQuery.each is not asynchronous even if your Ajax call is.

I suggest reading up on jQuery.each and on this great SO answer.

Best of luck.

Community
  • 1
  • 1
PhilTrep
  • 1,521
  • 1
  • 10
  • 23