0

I have a ajax function where I am trying to Download a file and then redirecting to next page. It is working perfectly in chrome, but not in firefox and IE. This is my JS code

function GenerateMsi() {
            var obj = {};
            obj.establishmentGuid = '@Model.InformEstablishmentGuid';
            obj.networkType = $('input[name=sit]:checked').val();
            $.ajax({
                type: "POST",
                url: "@Url.Action("GenerateMsi", "Establishment")",
                data: obj,
                success: function (data) {
                    var uri = data.msiLocation;
                    uri = uri.replace(/\s+/g, '%20');
                    this.link = document.createElement("a");
                    this.link.href = uri;

                    //set the visibility hidden so it will not effect on your web-layout
                    this.link.hidden = true;
                    this.link.download = data.filename;

                    //this part will append the anchor tag and remove it after automatic click
                    document.body.appendChild(this.link);
                    this.link.click();
                    document.body.removeChild(this.link);
                },
                complete: function (data) {
                    window.location.href= data.redirectUrl;
                },
                error: function () {
                    alert("Some error occured in the server!")
                }
            });
        }

NB: If that download function is not there, it is redirecting to the next page. Please help me to solve the issue

S M
  • 3,133
  • 5
  • 30
  • 59

0 Answers0