Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use callback on javascript class function
    primarykey
    data
    text
    <p>how to sue java script callback on javascript class function. i have to call SalesExceptionNMGList.getParam() after TerritoryList.getParam(); completes using callback only. please suggest to solve the problem.</p> <pre><code>$(document).ready (function() { TerritoryList.getParam();//takes 1 minutes to complete SalesExceptionNMGList.getParam();//call when TerritoryList.getParam() completes and get ajax response. using callback }); var TerritoryList={ act:null, division:null, region:null, cluster:null, getParam:function(){ this.act='getTerritory'; this.division = $("#division").val(); this.region = $("#region").val(); this.cluster = $("#cluster").val(); var TA = []; TA.push("act="); TA.push(this.act); TA.push("&amp;division="); TA.push(this.division); TA.push("&amp;region="); TA.push(this.region); TA.push("&amp;cluster="); TA.push(this.cluster); resetHierarchy("#territory,#wssTerritory,#freeWssTerritory,#territorycount,#wsscount"); if(this.cluster != "-1"){ this.callToServer(TA.join("")); } }, callToServer:function(arg){ var a="FillHeirarchy.do?"+arg; AJAX.setParams("POST",a,"text"); $("#loader").show(); AJAX.mXHTTPRequest(AJAX,this.handleServerResponse,true); return false }, handleServerResponse:function(response){ if (typeof callback === "function") { callback(response); } var resultobject=eval("("+response+")"); var res=resultobject.list; var h = "#territory"; var TA = []; TA.push("&lt;option value='-1' selected='true'&gt;Select Territory&lt;/option&gt;"); TA.push("&lt;option value='0' &gt; All &lt;/option&gt;"); if(res.length&gt;0) { if(res.length == 1) { var divisionVal=res[0]; var divisionArr=divisionVal.split("$"); TA.push("&lt;option value='"+divisionArr[0]+"' title='"+divisionArr[1].capitalize()+"'&gt;"+divisionArr[1].toUpperCase()+"&lt;/option&gt;"); } else { for (var i=0; i&lt;res.length; i++) { divisionVal=res[i]; divisionArr=divisionVal.split("$"); TA.push("&lt;option value='"+divisionArr[0]+"' title='"+divisionArr[1].capitalize()+"'&gt;"+divisionArr[1].toUpperCase()+"&lt;/option&gt;"); } } $(h).html(TA.join("")); // WssTerritoryList.getParam(); delete (TA); } $("#loader").hide(); $("#territorycount").html(res.length); selectedAll1('territory'); } }; var SalesExceptionNMGList={ act:null, division:null, region:null, cluster:null, territory:null, wssTerritory:null, searchType:null, exception:null, getParam:function(){ this.act='salesExceptionNMGList'; this.division = $("#division").val(); this.region = $("#region").val(); this.cluster = $("#cluster").val(); this.territory = $("#territory").val(); this.wssTerritory = $("#wssTerritory").val(); alert("wss= "+this.wssTerritory); alert("territory= "+this.territory); alert("cluster= "+this.cluster); if (this.wssTerritory!="-1") { this.searchType="wss"; } else if (this.territory!="-1") { this.searchType="territory"; } else if (this.cluster!="-1") { this.searchType="cluster"; } else{ this.searchType="cluster"; } if($('#chkSEOPG').is(':checked')){ this.exception="OPG"; }else if($('#chkSEPLB').is(':checked')){ this.exception="PLB"; }else{ this.exception="-1"; } var TA = []; TA.push("act="); TA.push(this.act); TA.push("&amp;division="); TA.push(this.division); TA.push("&amp;searchType="); TA.push(this.searchType); TA.push("&amp;salesException="); TA.push(this.exception); // resetHierarchy("#freeWssTerritory"); this.callToServer(TA.join("")); }, callToServer:function(arg){ var a="FillHeirarchy.do?"+arg; alert(a); AJAX.setParams("POST",a,"text"); $("#loader").show(); AJAX.mXHTTPRequest(AJAX,this.handleServerResponse,true); return false }, handleServerResponse:function(response){ alert(response); var resultobject=eval("("+response+")"); var res=resultobject.list; var h = "#product_nmg"; var TA = []; TA.push("&lt;option value='-1' selected='true'&gt;Select NMG&lt;/option&gt;"); TA.push("&lt;option value='0' &gt;All&lt;/option&gt;"); if(res.length == 1) { var divisionVal=res[0]; var divisionArr=divisionVal.split("$"); TA.push("&lt;option value='"+divisionArr[0]+"' title='"+divisionArr[1].capitalize()+"'&gt;"+divisionArr[1].capitalize()+"&lt;/option&gt;"); } else { for (var i=0; i&lt;res.length; i++) { divisionVal=res[i]; divisionArr=divisionVal.split("$"); TA.push("&lt;option value='"+divisionArr[0]+"' title='"+divisionArr[1].capitalize()+"'&gt;"+divisionArr[1].capitalize()+"&lt;/option&gt;"); } } $(h).html(TA.join("")); // ClusterList.getParam(); delete (TA); $("#loader").hide(); } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload