Ask a phpexcel about the problem

Source: Internet
Author: User
Ask a phpexcel question
Recently in a project, you need to export the query processed tabular data to the client's Excel, because the page table data is not directly queried from the database, but calculated and so on. There is a button on the page, the OnClick event uses Ajax to pass some necessary parameters to the server, exportexcel.php the file to receive the parameter and then query the database, processed, and finally exported to the Excel file using Phpexcel.
So the problem is, the test found that Ajax has been executed, but the browser will not pop-up window to download the exported Excel file, no response. What to do to use Ajax to pass parameters to exportexcel.php, and to pop up the download save window?
Code for AJAX
function Excel (Url1,params)
{
try{
var xhr = new XMLHttpRequest ();
}catch (Trymicrosoft) {
try{
var xhr = new ActiveXObject ("Msxml2.xmlhttp");
}catch (Othermicrosoft) {
try{
var xhr = new ActiveXObject ("Microsoft.XMLHTTP");
}catch (failed) {
var xhr = false;
}
}
}
var url=url1+ "?" + "&r=" +math.random ();
Xhr.open ("POST", url,true); Readystate=1
Xhr.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xhr.send (params);
xhr.onreadystatechange= function ()
{
If equals 4, indicates that the interaction is complete, we can take out the contents returned by the server
if (xhr.readystate== 4 && xhr.status== 200)
{

}
}
}

exportexcel.php code is not a problem, I tested it alone, can pop up the download window.
Please expert guidance under, how to do, have troubled me for several days, has not figured out a way to

------Solution--------------------
If you don't use Ajax and pass parameters with a connection, do you do that?
------Solution--------------------
Correct it.

function Excel (Url1,params) {
Window.location = url1+ "?" + "&r=" +math.random () + "&" + params;
}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.