0

it's somewhat confusing for me I am getting result through my ajax call I am converting that into my user defined object script and I am pushing that result into array and I am converting that into JSOn data like this

function orgNameAndIdListClass(id, name) {
  this.label = name;
  this.value = name;
  this.idValue = id;
}
orgNameAndIdList = [];



$.get("../organizationSourceMapping/listOrg.htm?sourceMasterFilter=",
function(response) {
  if (response.status == "LIST_SUCCESS") {
    var listOrgIdAndName = response.successObject.listOrgIdAndName;
    for (var i = 0; i < listOrgIdAndName.length; i++) {
      var orgNameIds = new orgNameAndIdListClass(listOrgIdAndName[i].id, listOrgIdAndName[i].organizationFullName);
      orgNameAndIdList.push(orgNameIds);
    }
  }, 'json')
.fail(function(response) {
  $('#page-wrapper').mask(
    response.status + "**********" + response.statusText);
}); console.log(JSON.stringify(orgNameAndIdList))

});


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

my orgNameAndIdList each object shows data like

idValue:1
label:"org1"
value:"org1"
epascarello
  • 204,599
  • 20
  • 195
  • 236
LowCool
  • 1,187
  • 5
  • 25
  • 51
  • what is listOrgIdAndName ? if it's an array then you have to loop through the array and then create the new object – karthick May 30 '17 at 17:33
  • And can you explain a bit more on what you are expecting – karthick May 30 '17 at 17:33
  • 1
    Can we see more code than what you provided.... I think the issue might be asynchronous related and not related to this code. – epascarello May 30 '17 at 17:33
  • @epascarello:added full code please ignore parentheses mismatch it may due to I removed redundant code – LowCool May 30 '17 at 18:01
  • And I was right.... You ordered a pizza on the phone and as soon as you hang up you try to eat the pizza you just ordered. You did not wait for it to be delivered. That is what the callback is for. – epascarello May 30 '17 at 18:04

0 Answers0