AJAX problem with php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sheldonlg

    AJAX problem with php

    I haven't received an answer with my other post, so I am rephrasing it here.

    In php I have a 2D array which I "print". The headers force it to be a
    file on the user's system. The user receives a pop-up that asks him if
    he wants to open it or save it. (Of course, he can simply cancel). The
    file I send is in an Excel readable file. This works fine for simple
    systems where the page is submitted and then the action is performed by php.

    Now for the problem. Using AJAX I have a very complicated page being
    displayed that takes a while to build. There are numerous buttons and
    "links" on this page. They all operate via AJAX. One of those buttons
    is to generate the Excel file. The problem is that if I direct the AJAX
    target to a div on the screen, it simply prints and ignores the headers
    from php to output to a file. If I don't buffer the output to send it
    all at once, then the print statement is not understood by AJAX and I
    get an error message about an illegal string.

    How do change the AJAX target, and/or what else must I do, so that it
    will operate the same as with simple web systems and generate a file and
    a popup to the user?
  • Erwin Moller

    #2
    Re: AJAX problem with php

    sheldonlg schreef:
    I haven't received an answer with my other post, so I am rephrasing it
    here.
    >
    In php I have a 2D array which I "print". The headers force it to be a
    file on the user's system. The user receives a pop-up that asks him if
    he wants to open it or save it. (Of course, he can simply cancel). The
    file I send is in an Excel readable file. This works fine for simple
    systems where the page is submitted and then the action is performed by
    php.
    >
    Now for the problem. Using AJAX I have a very complicated page being
    displayed that takes a while to build. There are numerous buttons and
    "links" on this page. They all operate via AJAX. One of those buttons
    is to generate the Excel file. The problem is that if I direct the AJAX
    target to a div on the screen, it simply prints and ignores the headers
    from php to output to a file. If I don't buffer the output to send it
    all at once, then the print statement is not understood by AJAX and I
    get an error message about an illegal string.
    Hi,

    I fail to see why you use Ajax for this.
    The response your PHP script gives you is catched in your HtppXML
    Object, which is of course NOT a new window.

    So why use Ajax for something it is not suited for?

    Why not simply open a new window which loads the content?

    <a href="myPHPExce lthingy.php" target="someNew Window">Excel</a>

    Regards,
    Erwin Moller
    >
    How do change the AJAX target, and/or what else must I do, so that it
    will operate the same as with simple web systems and generate a file and
    a popup to the user?

    Comment

    • sheldonlg

      #3
      Re: AJAX problem with php

      Erwin Moller wrote:
      sheldonlg schreef:
      >I haven't received an answer with my other post, so I am rephrasing it
      >here.
      >>
      >In php I have a 2D array which I "print". The headers force it to be
      >a file on the user's system. The user receives a pop-up that asks him
      >if he wants to open it or save it. (Of course, he can simply
      >cancel). The file I send is in an Excel readable file. This works
      >fine for simple systems where the page is submitted and then the
      >action is performed by php.
      >>
      >Now for the problem. Using AJAX I have a very complicated page being
      >displayed that takes a while to build. There are numerous buttons and
      >"links" on this page. They all operate via AJAX. One of those buttons
      >is to generate the Excel file. The problem is that if I direct the
      >AJAX target to a div on the screen, it simply prints and ignores the
      >headers from php to output to a file. If I don't buffer the output to
      >send it all at once, then the print statement is not understood by
      >AJAX and I get an error message about an illegal string.
      >
      Hi,
      >
      I fail to see why you use Ajax for this.
      The response your PHP script gives you is catched in your HtppXML
      Object, which is of course NOT a new window.
      >
      So why use Ajax for something it is not suited for?
      >
      Why not simply open a new window which loads the content?
      >
      <a href="myPHPExce lthingy.php" target="someNew Window">Excel</a>
      >
      Regards,
      Erwin Moller
      The whole application is built on an AJAX framework. I suppose that for
      this one item I could do what you say and go directly to a php file
      which pulls in the class to create the array, and then uses the class to
      export the array to excel and then returns. No new target window would
      be used. It bypasses the framework, but my boss might go along with
      this. Thanks. I didn't think of that approach.

      Comment

      • abaqueiro

        #4
        Re: AJAX problem with php

        well, use a normal GET/POST using a target "_blank" or other, so it
        opens in a new window

        Comment

        • sheldonlg

          #5
          Re: AJAX problem with php

          abaqueiro wrote:
          well, use a normal GET/POST using a target "_blank" or other, so it
          opens in a new window
          >
          It's not as simple as that. The AJAX swallows everything. I had to
          work outside of AJAX.

          Comment

          Working...