I am working on angularjs services. I got some callback response from my API endpoint. I am using angular jsonP to fetch callback response I have used jsonpCallbackParam: 'jsonpCallback' to parse my callback response. But this jsonpCallback function is not triggered. I have attached my response below.
projectInstance.jsonpCallback("getActiveProduct",{"totalRecords":null,"projectSnapShot":[{"projectId":"333333","projectNumber":"123456","projectStatus":"Active"}]})
Here is my service code:
getActiveProduct: function() {
var deferred = $q.defer();
var url = "myserver/getproject.json"
projectInstance={};
$http.jsonp(url, {
jsonpCallbackParam: 'jsonpCallback',
data: ''
}).then(function(data) {
deferred.resolve(data.data);
}, function(error) {
console.log(error);
return deferred.reject(err);
});
return deferred.promise;}
Here is my jsonpCallback function
jsonpCallback: function(commandName, responseData) {
if (commandName == "getActiveProduct") {
var jsonObject = responseData;
var projectArray = [];
angular.forEach(jsonObject.projectSnapShot, function(index, item) {
projectArray.push(item);
console.log(projectArray);
});
}
Here i attached my service end point .It automatically attach angular.callbacks._0
myserver/getproject.json?callback=angular.callbacks._0
I have attached my console error below
Uncaught TypeError: Cannot read property 'jsonpCallback' of null
Its throws error response like
{data: false, status: 404, headers: ƒ, config: {…}, statusText: "error", …}
I got response in network Tab . But while parsing in front end because of this JsonpCallback its throws console error.How to fix this issue?