Force download file with jquery and asp.net server side function call
<p>i have one image and i was just trying to show save as dialog box for downloading that image by jquery ajax call. when some one will click on button then a client side code run and here code as follows</p>

<pre><code>$("#btnSaveAsImage").click(function () {
    if (_TrackNumber == '') {
        alert('Track Number is not valid');
        return;
    }
    var fname = _TrackNumber + '.gif';
    var DTO = { FileName: fname };

    jQuery.ajax({
        type: "POST",
        url: "UPSLabelFormUK.aspx/SaveAs",
        data: JSON.stringify(DTO),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            var retVal = data.d;
            alert(retVal);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus);
        }
    });
    return false;
});
</code></pre>

<p>and this client side code actually call my server side function. the server side function look like</p>

<pre><code>[WebMethod]
    public static void SaveAs(string FileName)
    {
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.WriteFile(HttpContext.Current.Server.MapPath(@"~/UPS_New/LabelImages/" + FileName));
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.Close();
    }
</code></pre>

<p>when server side function execution end then jsuery show a error message like parse error. i just do not understand why the error comes and why save as dialog is not coming......any idea please share with me. thanks</p>
