1

I am aware that this question has been asked before and I had the solution working last week based on the responses in the answers provided, nothing has changed and all of a sudden the jquery has stopped working.

I am using an Ajax call (below) that returns me a string that I assign to a hidden link on a page to force the download of a file from my works LAN.

$(document).ready(function () {

$(".excelLoader").hide();

$('.extract')
    .on('click',
        function () {

            var rh = Number($(this.id).selector);

            console.log("clicked: " + rh);
            var loader = "load_" + rh;
            var excel = "excel_" + rh;
            console.log(loader);
            $("." + excel).hide();
            $("." + loader).show();

            var params = {
                responseHeaderId: rh
            }

            $.ajax({
                type: "POST",
                url: "SubmissionTracker.aspx/ExportFile",
                data: JSON.stringify(params),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {

                    $("#hiddenLink").attr("href", data.d);
                    console.log($("#hiddenLink").val());
                    $("#hiddenLink").click();
                    $("." + excel).show();
                    $("." + loader).hide();

                },
                error: function (data) {
                    console.log("error :" + data);
                    console.log(data);
                    $("." + excel).show();
                    $("." + loader).hide();
                }
            });
        });

})

the issue that I have now is that the href is not being set, so the click event fires but with nothing to fetch.

The line I believe to be the issue is $("#hiddenLink").attr("href", data.d); the line it is trying work with in my ASP.Net Webforms page is <a id="hiddenLink" href=""></a>.

I have cleared my Cache, removed any temporary files that may have existed but still cannot reproduce the positive results I had last week.

Any and all help bery much appreciated.

-----------update----------------

issue appears to be on the click event of the link. JQuery that I am usering is version jquery-1.11.3.js which is referenced first, and the js file where this is referenced is in the middle of all the other referenced files.

Simon Price
  • 3,011
  • 3
  • 34
  • 98
  • what is the value of `data.d` – brk Jul 26 '16 at 09:46
  • `console.log(data);` in your success callback. What is the value? – Brett Gregson Jul 26 '16 at 09:46
  • I get the right value back which is the FQN of the path of the file. Ive just looked at and changed the value to an external site, saw the value of the href change, but it was the click event that didn't fire – Simon Price Jul 26 '16 at 09:51
  • something of interest, in visual studio, when breaking on a breakpoint and looking at the value `$("#hiddenLink").href;` is undefined, yet, `$("#hiddenLink")[0].href;` is giving me the right response, however the click event it still not giving me anything back – Simon Price Jul 26 '16 at 10:04
  • are you sure your selected element is exist with that name in the DOM? As your question tag, usually asp.net change the object id's. i suggest you to select the anchor (``) element using class. `$(".hiddenLink")` – Fadhly Permata Jul 26 '16 at 10:04
  • Duplicate of http://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery – Tomalak Jul 26 '16 at 10:08
  • @Tomalak, yes if you read my question, I say that I know this has been asked before, its how I found how to do what I am trying to do. – Simon Price Jul 26 '16 at 10:09
  • @FadhlyPermata yes, checking the source code, it does exists, and im using a standard HTML control rather than an ASP.Net control. Can you give me a fuller example of what you mean. I think I have an idea but just want to be clear – Simon Price Jul 26 '16 at 10:10
  • @SimonPrice: yes, even you've used native HTML control, when you put `runat="server"` attribute, asp will change the id for those control. For example `
    ` become `
    `.
    – Fadhly Permata Jul 26 '16 at 10:16
  • yes, im aware of that and as stated in my code the link is as it appears here `` there is no `runat="server"` tags contained within it to make it work as a server control – Simon Price Jul 26 '16 at 10:20

0 Answers0