In my application, Asp web service returns JSON with object name called 'd' so I access that 'd' object the in the application as follows,

enter image description here

GetBranchOrRegionDataSourceSuccess: function (result, status, init) {
    "use strict";
    var regions = JSON.parse(result.d);
}

I called this function inside the Ajax success call.

Now the problem is I have Jquery function called searchLocations, Inside that function, I need to call this function. and need to pass the parameters.

I tried like this,

var jsonResult = JSON.stringify({'d':result});
  this.GetBranchOrRegionDataSourceSuccess(jsonResult,"Success", true); //here I need to call the function

this is my complete function.

function searchName(prov,tree) {
  var result = [];

  let searchKey = new RegExp(prov, "i");

  var objects = JSON.parse(json);
  for (obj of objects) {
    if (obj.Name.match(searchKey)) {

      result.push(obj); 

    } else {
      var toAdd = {"Id": obj.Id, "Name": obj.Name, "Branches": []};
      for (branch of obj.Branches) {
        if (branch.Name.match(searchKey)) {
          toAdd.Branches.push(branch);
        }
      }
      if (toAdd.Branches.length) {
        result.push(toAdd);
      }
    }
  }

  var jsonResult = JSON.stringify({'d':result});
  this.GetBranchOrRegionDataSourceSuccess(jsonResult,"Success", true); //here I need to call the function

}

But it makes error inside GetBranchOrRegionDataSourceSuccess on this line var regions = JSON.parse(result.d); How can I pass the result with 'd' object name

1 Answers

2
Phil On Best Solutions

GetBranchOrRegionDataSourceSuccess is expecting an object with property d.

The d property value needs to be a JSON string (which it will parse).

You want

let jsonResult = { d: JSON.stringify(result) }
this.GetBranchOrRegionDataSourceSuccess(jsonResult, 'Success', true)