TinyButStrong - the PHP Template Engine
Categories > OpenTBS with DOCX >

ExtSJ4, Ajax & Php. The browser don't propose me the document but the result is ok?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs

By: Bruno
Date: 2017-01-31
Time: 17:45

ExtSJ4, Ajax & Php. The browser don't propose me the document but the result is ok?

Dear All,

I try to use the demo inside my ExtJS program. I use a Ajax request to reach my php page.

        Ext.Ajax.request({
        url         : 'onetest.php',
        method      : 'GET',
        params: {
            pn      : 'xxxx'
        },
        success : function(){
            Ext.example.msg('Information', 'Your Word document is ready');
        },
        failure : function(){
            alert('Error');
        }

All works fine if I call directly the PHP page, my browser propose me the docx document,
but if I call my php page in a Ajax request, I reach it, and the result is not "translate" (I don't know how can I tell that)
With the chrome developper tool I see the result like this:

PK!kÖñק _[Content_Types].xml ¢( ´UËnÂ0¼Wê?D¾VÄÐCUU$ú8¶H¥`ì
X²—×ßw ª($”K¤ÄڙÙÙñf8Z›2YBˆÚٌ
Ò>KÀJ§´eìkòÖ{dIDa•(…Œm ²Q~{3œl<ĄªmÌØÑ?q匈©ó`é¤pÁ¤×0ã^Èo1~ßï?pé,‚ÅV,~€ $cð]âá+/œCëbJp,yÞÖUÔޗZ
$á|iÕ iÏ…– œ\¢J+8œ„©5S¦
ô]Íóá bQbòº&m[;¼jS5Q}?^ Œ%:wƤTY

I try to add header('xxx'); text before the TBS->show without success

header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Disposition: attachment;filename="' . $fileName . '"');

Do you have an idea about this problem ?

Thanks a lot for your help,
Sincerely,
Bruno
By: Skrol29
Date: 2017-02-02
Time: 20:21

Re: ExtSJ4, Ajax & Php. The browser don't propose me the document but the result is ok?

Hello Bruno,

The problem is not OpenTBS but the way you're try to get the document.
Ajax does HttpRequest calls that produce a result which is catchable only by Javascript. You cannot have a download from the navigator as a result of an Ajax call.
You can have your download from your page only by calling the link directy.
By: Bruno
Date: 2017-02-03
Time: 08:54

Re: ExtSJ4, Ajax & Php. The browser don't propose me the document but the result is ok?

Hi Skrol29,

Thank you for your answer, I will investigate right now to find a solution in my Ajax answer.

Have a nice day,
Bruno