Wait for JSON response inside a FOREACH

Discussion in 'jQuery' started by marcoVera, Sep 9, 2014.

  1. #1
    Hello,

    I have a doubt regarding how to show JSON reponse inside a FOREACH, what is happening is that FOREACH is not waiting the necesary time to get the response form JSON.

    I was searching some info. and I could find out that I can use queue or async.foreach but is not working for me (or maybe I'm not implementing it correctly)
    The issue maybe could be because I'm using JSON inside a function (function getTotal(idProcess,day)).

    
    function getProcesos(e){
      //I run here a JSON process
      $.each( jsonStr, function( key, val ) {
      var spanProceso = document.createElement('span');
      spanProceso.style.fontSize = setLimitSize;
      spanLunes.appendChild(document.createTextNode(" "+getTotal(val.ID,1)+"/"+val.Nombres));
      td2.appendChild(spanProceso );
      }
    function getTotal(idProcess,day){
      //I run here a JSON Process and return a result with the below variable.
      return getTotalUsers
      }
    
    Code (markup):
    As you can see I have inside the FOREACH a JSON call that is in a FUNCTION but I don't know how send the action to FOREACH to wait for the JSON response.

    Any Idea :S?

    Thanks in advance
     
    marcoVera, Sep 9, 2014 IP