这是我的JavaScript代码:
$.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.");
}
})
但是在这里我两次调用了api。首先,我检查是否有可用数据,然后我将要求下载如何通过单次调用来实现。