code_junkie

Use jQuery to send Excel data using AJAX

Nov 11th, 2011
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. function SendToExcel() {
  2. $.ajax({
  3. type: "GET",
  4. url: "/Search.aspx",
  5. contentType: "application/vnd.ms-excel",
  6. dataType: "text",
  7. data: "{id: '" + "asdf" + "'}",
  8. success: function(data) {
  9. alert(data);
  10. },
  11. error: function (XMLHttpRequest, textStatus, errorThrown) {
  12. alert(XMLHttpRequest.responseText);
  13. }});
  14. }
  15.  
  16. function SendToExcel() {
  17. var dataString = 'type=excel' +
  18. '&Number=' + $('#txtNumber').val() +
  19. '&Reference=' + $('#txtReference').val()
  20.  
  21. $("#sltCTPick option").each(function (i) {
  22. dataString = dataString + '&Columns=' + this.value;
  23. });
  24.  
  25. top.iExcelHelper.location.href = "/Reports/JobSearchResults.aspx?" + dataString;;
  26. }
  27.  
  28. function exportExcel(){
  29. var inputs = $("#myForm").serialize();
  30. var url = '/ajaxresponse.php?select=exportExcel&'+inputs;
  31. location.href = url;
  32. }
  33.  
  34. case 'exportExcel':{
  35. ob_end_clean();
  36. header("Content-type: application/vnd.ms-excel");
  37. header("Content-Disposition: attachment;
  38. filename=exportFile.xls");
  39. echo $html->List($bd->ResultSet($_GET));
  40. }
Add Comment
Please, Sign In to add comment