1

Edit: Not sure why this was marked as a duplicate given that the original doesn't even really have an answer other than "use this third party tool that adds extra interface stuff that you probably don't want or need". The reason I was using ajax is because I need to send an array of ids and I'm not sure how to do it other than with ajax. I figured out what I need to do, so I don't really need any more help from this post, but this definitely isn't a duplicate question, and even if it were, there isn't a real answer to the original.

I've been trying to get a link that will download a file generated by my export script. However, I can't get it to get the returned file. This is the JS function I've been using...

function sendSelected(path) {
    var ids;
    ids = jQuery("#grid").jqGrid('getGridParam', 'selarrrow');
    if (ids.length > 0) {
        alert("");
        $.ajax({
            url: path,
            data: { ids: ids },
            type: "POST",
            traditional: true,
        });
    } else {
        alert("You have not selected any rows.");
        return false;
    }
}

and then here's the HTML portion...

<input type="submit" name="command" value="Export" />
<script type="text/javascript">
    jQuery("#export").click(function () { sendSelected("/Forms/Export"); });
</script>

This all works fine, except my exporter ends with document.Save(response, "file.pdf"); and the page isn't getting this back. If I change it to document.Save(response, @"C:\some\location\to\save\at.pdf"); the file is created there, so I know it's not a problem creating the file. Also, if I just create a standard form that points to /Forms/Export and then manually enter the ids, I can download the file fine, but that doesn't work for my implementation.

davidjosepha
  • 117
  • 3
  • 14

1 Answers1

1

$.ajax will not work, i was attempting something similar recently but ended up with different solution. Simply have a form with hidden input and then in your sendSelected set the field and action and then submit form.

    $("#hiddenField").val(data);
    $("#yourForm").attr("action", path)
    $("#yourForm").submit();
Konstantin
  • 3,254
  • 15
  • 20