1. #1
    Ext User
    Join Date
    Jul 2009
    Posts
    37
    Vote Rating
    1
    DarkStarDS is on a distinguished road

      0  

    Default How to send HTTP headers to client with ExtJS

    How to send HTTP headers to client with ExtJS


    Hello, I wish I could do the same as this php code in extjs. The treatment (CSV export) is client side. So, I have sent the data by data url but unfortunalety it does not work on IE8 due to length restriction of the url (FF and chrome it's ok). So I want now to send http headers to send my data. Unless you have another solution ?

    PHP Code:
    switch( $tid )
            {
                case 
    "1"    $ctype "application/pdf"; break;
                case 
    "2"    $ctype "application/xml"; break;
                default        : return 
    "The file type is corrupt. This is a fairly big problem - please contact us!";
            }

            
    header"Pragma: public" );
            
    header"Expires: 0" );
            
    header"Cache-Control: must-revalidate, post-check=0, pre-check=0" );
            
    header"Cache-Control: private"false ); 
             
    header"Content-Type: $ctype);
            
    header"Content-Disposition: attachment; filename=\"" basename$fileDir ) . "\";" );
            
    header"Content-Transfer-Encoding: binary" );
            
    header"Content-Length: " filesize$fileDir ) );

            
    $byteCount = @readfile"$fileDir); 

  2. #2
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,664
    Vote Rating
    7
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    have a look to http://extjs.com/deploy/dev/docs/?class=Ext.Ajax
    You should be able to define your headers in "headers"
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  3. #3
    Ext User
    Join Date
    Jul 2009
    Posts
    37
    Vote Rating
    1
    DarkStarDS is on a distinguished road

      0  

    Default


    But Ajax is for server request ? So I don't want precisely to send something to the server to win time !

  4. #4
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,664
    Vote Rating
    7
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    i don't know how exactly you send your data, but Ajax extends Connection, which is the basic one. Examine this object and you see how to add headers.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  5. #5
    Ext User
    Join Date
    Jul 2009
    Posts
    37
    Vote Rating
    1
    DarkStarDS is on a distinguished road

      0  

    Default


    Well, AJAX means server request, so anyway that is not a solution for what I am looking for. Extjs is a Javascript-based framework so finally my question is: is there a javascript function that allows to send http headers from client to browser ?

  6. #6
    Sencha User
    Join Date
    Jun 2009
    Posts
    47
    Vote Rating
    0
    curlybracket is on a distinguished road

      0  

    Default


    How should that happen? The browser is the client.

  7. #7
    Ext User
    Join Date
    Jul 2009
    Posts
    37
    Vote Rating
    1
    DarkStarDS is on a distinguished road

      0  

    Default


    Yes, I mean sending headers from client to client. To trigger a download prompt from client. I wish I could do the same in javascript as the php code above.

  8. #8
    Sencha User
    Join Date
    Jun 2009
    Posts
    47
    Vote Rating
    0
    curlybracket is on a distinguished road

      0  

    Default


    Quote Originally Posted by DarkStarDS View Post
    Yes, I mean sending headers from client to client. To trigger a download prompt from client. I wish I could do the same in javascript as the php code above.
    I'm quite sure this is not possible.

  9. #9
    Ext User
    Join Date
    Aug 2009
    Posts
    588
    Vote Rating
    1
    Mike Robinson is on a distinguished road

      0  

    Default


    Stop and think about it for a sec... There are two computers involved here: the client (that would be, "your PC"), and the server (which runs the web-page you're talking to).

    php (or ColdFusion or Ruby or what-have-you) is server-side technology. It's getting your AJAX or HTML requests-for-data and sending back JSON or HTML data to you. This is probably where you need to generate your headers.

    ExtJS (and AJAX in general...) is client-side. It's running on your PC.

    It is true that both computers are talking to one another using the HTTP protocol. (They may not be exchanging HTML data, but they are using HTTP.) When you send an AJAX request, you therefore can indeed set standard or custom headers, because headers are part of the fundamental definition of what "the HTTP protocol" is. But when you present us with a php example, that tells me that you're interested in the headers that the server is sending to the client ... not the headers that the client (ExtJS) may be sending to the server. All of ExtJS has nothing at all to do with "what the host says."

  10. #10
    Ext User
    Join Date
    Jul 2009
    Posts
    37
    Vote Rating
    1
    DarkStarDS is on a distinguished road

      0  

    Default


    This is also what I think... But I don't have any absolute certainty, a page on the w3c or whatever that says it is not possible, that's why I am posting this thread...