Javascript 将GET响应传递给POST
我正试图将依赖于所选id的多个数据映射传递给导出到Excel方法 我尝试使用AngularJS将GET响应中的JSON数组传递给POST,代码如下:Javascript 将GET响应传递给POST,javascript,json,angularjs,post,get,Javascript,Json,Angularjs,Post,Get,我正试图将依赖于所选id的多个数据映射传递给导出到Excel方法 我尝试使用AngularJS将GET响应中的JSON数组传递给POST,代码如下: $scope.exportExcel = function() { var id='?'; angular.forEach($scope.selection, function(value, key) { id = id + "id=" + value + '&'; }); $http.get(searchUrl + id).su
$scope.exportExcel = function() {
var id='?';
angular.forEach($scope.selection, function(value, key) {
id = id + "id=" + value + '&';
});
$http.get(searchUrl + id).success(
function(response) {
$http.post(exportUrl, response);
}
)}
GET的响应将是一个JSON数组,看起来像这样,假设Jason和Fred都被选中:
response = [{'id':'Jason', 'number':1}, {'id':'Fred', 'number':2}]
我已经开发了Java代码,因此POST方法的输入应该与上面的数组类似
我希望用户选择id,按下导出按钮,并立即获得下载对话框。没有其他屏幕更改或加载
这是否可行?我的POST命令能否从GET接收JSONArray响应并成功导出?没有理由这不起作用。一旦GET操作完成并调用其on success函数,您的代码就进入了一个全新的域,POST操作将正常运行,它不关心也不知道数据来自何处。只需快速尝试;如果您无法使用此选项,请尝试此选项。我需要有关值外观的更多信息-我不知道您正在使用的库:
$scope.exportExcel = function() {
var id;
angular.forEach($scope.selection, function(value, key) {
id = (id?id+"&":"?")
+ "id["+key+"]=" + encodeURIComponent(value.id)
+ "&number["+key+"]=" + value.number;
});
$http.get(searchUrl + id).success(
function(response) {
$http.post(exportUrl, response);
}
)}
是的,它起作用了。毕竟,我只是需要肯定。我对它进行了测试,效果良好。谢谢那些回答的人