title: Downloading Excel File via webmethod response by ajax calling
body: <p>I have created a webmethod and  the method just send a Excel file as webresponse.When i run only the webmethod it works fine as want
  <a href="https://i.stack.imgur.com/vALa7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vALa7.jpg" alt="enter image description here"></a></p>
  
  <p>My webmethod is following:</p>
  
  <pre><code> public void Export_ex(string elem)
      {
  
              string elements = elem;
              HttpContext.Current.Response.ContentType = "data:application/vnd.ms-excel";
              HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=Print.xls");
              HttpContext.Current.Response.Write("&lt;html xmlns:x=\"urn:schemas-microsoft-com:office:excel\"&gt;");
              HttpContext.Current.Response.Write("&lt;head&gt;");
              HttpContext.Current.Response.Write("&lt;div&gt;");
              HttpContext.Current.Response.Write("&lt;META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-     8\"&gt;");
              HttpContext.Current.Response.Write("&lt;!--[if gte mso 9]&gt;&lt;xml&gt;");
              HttpContext.Current.Response.Write("&lt;x:ExcelWorkbook&gt;");
              HttpContext.Current.Response.Write("&lt;x:ExcelWorksheets&gt;");
              HttpContext.Current.Response.Write("&lt;x:ExcelWorksheet&gt;");
              HttpContext.Current.Response.Write("&lt;x:Name&gt;Report Data&lt;/x:Name&gt;");
              HttpContext.Current.Response.Write("&lt;x:WorksheetOptions&gt;");
              HttpContext.Current.Response.Write("&lt;x:ValidPrinterInfo/&gt;");
              HttpContext.Current.Response.Write("&lt;/x:Print&gt;");
              HttpContext.Current.Response.Write("&lt;/x:WorksheetOptions&gt;");
              HttpContext.Current.Response.Write("&lt;/x:ExcelWorksheet&gt;");
              HttpContext.Current.Response.Write("&lt;/x:ExcelWorksheets&gt;");
              HttpContext.Current.Response.Write("&lt;/x:ExcelWorkbook&gt;");
              HttpContext.Current.Response.Write("&lt;/xml&gt;");
              HttpContext.Current.Response.Write("&lt;![endif]--&gt; ");
              HttpContext.Current.Response.Write("&lt;/head&gt;");
              HttpContext.Current.Response.Write(elements);
  
              HttpContext.Current.Response.Flush();
             // HttpContext.Current.Response.End();
  
  
          }
  </code></pre>
  
  <p>but when i call it from javascript function by ajax calling nothing happened. My ajax method is following :</p>
  
  <pre><code> var str = "something"
               var data = { elem: str };
               $.ajax({
                   type: 'POST',
                   url: "ImageSaving.asmx/Export_ex",
                   data: JSON.stringify(data),
                   contentType: "application/json; charset=utf-8",
                   mimeType: 'application/vnd.ms-excel',
                   success: function (response) {
                       var show = response.d;
  
                    },
                   failure: function (msg) {
                       alert("Error occur, could not load the service.");
                   }
               });
  </code></pre>
  
  <p>I could not understand where i am getting wrong?? Any suggestion regarding this? </p>