You should avoid sending JSON requests using GET. Try it like this:
var _ids = [ 'e2845bd4-9b3c-4342-bdd5-caa992450cb9', '566ddb9d-4337-4ed7-b1b3-51ff227ca96c', '25bc7095-a12b-4b30-aabe-1ee0ac199594' ]; $.ajax({ url: '@Url.Action("ZipResults", "TheController")', type: 'GET', data: { ids: _ids }, dataType: 'json', traditional: true, success: function() {
In doing so, I see that you are invoking some kind of controller action that returns the uploaded file. You should not use AJAX for this. The reason for this is that in your callback you will get the contents of the ZIP file, but you cannot handle it. You cannot save it to the client computer, you cannot offer the user to choose a save location, you are pretty much ruined.
Thus, no AJAX calls if you want to upload a file. You can use a simple anchor:
@Html.ActionLink("download zip", "ZipResults", "TheController", null, new { id = "download" })
and then:
$(function() { $('#download').click(function() { var _ids = [ 'e2845bd4-9b3c-4342-bdd5-caa992450cb9', '566ddb9d-4337-4ed7-b1b3-51ff227ca96c', '25bc7095-a12b-4b30-aabe-1ee0ac199594' ]; var url = this.href; for (var i = 0; i < _ids.length; i++) { if (url.indexOf('?') > 0) { url += '&ids=' + encodeURIComponent(_ids[i]); } else { url += '?ids=' + encodeURIComponent(_ids[i]); } } window.location.href = url; return false; }); });
source share