This is my JavaScript code:
$.ajax({
type: 'GET',
url: GlobalConstant.serviceURL + "/CampaignReport/GetCampaignWiseTransactionData2?CampaignId=" + $scope.tempFilter.campaignId + "&endDate=" + JSON.parse(JSON.stringify($scope.tempFilter.endDate)) + "&startDate=" + JSON.parse(JSON.stringify($scope.tempFilter.startDate)),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (res) {
if (typeof res === 'string') {
toastr.error(res); // Data Not Available
}
else {
//Return ResponseMessageResult of C#
window.location.href = GlobalConstant.serviceURL + "/CampaignReport/GetCampaignWiseTransactionData2?CampaignId=" + $scope.tempFilter.campaignId + "&endDate=" + JSON.parse(JSON.stringify($scope.tempFilter.endDate)) + "&startDate=" + JSON.parse(JSON.stringify($scope.tempFilter.startDate));
}
},
error: function (res) {
//Server Error
toastr.error("Oops something went wrong, Please try again later.");
}
})
But here I am calling the api two times. first I check there is data available or not if data available then I will call for download how can I achieve in single call.