[Cartoweb-users] trouble between ajax and sent header

Oliver Christen oliver.christen at camptocamp.com
Tue Apr 15 02:38:31 EDT 2008


Indeed, I havent thought about an action trigered via ajax.
Sadely the current ajax implementation do not handle mid-course canceling of 
the action.
The thing to do would be to modify a bit the actionRequest function in 
AjaxHandler.js so the new Ajax.Request call implement an "onLoaded" event 
which would allow you to interrupt the treatment after the request was sent. 
But the documentation of the prototype library 
(http://www.prototypejs.org/api/ajax/request) state the "onLoaded" event may 
not be supported by all browser. A less "clean" way would be to use the 
"onFailure" event which seems to be supported by all browser.

something like this:

cancelActionFlag: false,
cancelAction: function() {
  this.cancelActionFlag = true;
},
... (existing code) ...
doAction: function(actionId, argObject) {
  ... (existing code) ...
    var myAjax = new Ajax.Request(url,
            {method: 'post', postBody: queryObject.post,
             onComplete: function(response) {
             ... (existing code) ...
             }
             onLoaded: function() {
                if (cancelActionFlag) {
                  Logger.header('--- Action '+ actionId +' canceled ---');
                  return true;
                }
             }
             onFailure: function() {
                if (cancelActionFlag) {
                  Logger.header('--- Action '+ actionId +' canceled ---');
                  return true;
                }
             }
    });
},

and invoque AjaxHandler.cancelAction(); from the buildPostRequest of the 
ajax code of the plugin that triggered the ajax query

This is untested but you should get the idea.

By the way, one should be able to override any core ajax function by simply 
redefining the modified function in an new .js file loaded AFTER the main 
.js file (so puting it at the end of the <head> in the template should do 
the trick)
In this case, I presume a AjaxHandler.doAction = function(actionId, 
argObject) { ...(see above)... } *should* work.

regards
Oliver


> Hi Oliver,
> I think that sending an output by using the header and then using the
> instructions
> readfile();
> exit;
> is not a compliant way if there is ajax. It's a case "similar" to my
> previous (but solved) problem when I sent an echo.
> In this case there is something pending.
>
> The output is sent before the normal output of the plugIn. Even if after 
> the
> instructions :
> header()
> readfile
> exit
>
> there is the normal output of the plugIn, nothing is returned to the 
> client.
>
> Is there a way in order to force the re-sending of the template assign ? 
> or
> is there something like flush or similar to end the session in a correct 
> way
> ?
> This is the first time I use header but by reading on the Internet it is 
> not
> free from problem.
> I want to use this system so I can stop any direct access to the direcory.
>
> Please, any advice is welcome.
>
> Thanks and best regards
>
> Giu
>
>
>
>
>
> --------- Original Message --------
> Da: Oliver Christen <oliver.christen at camptocamp.com>
> To: cartoweb-users at lists.maptools.org <cartoweb-users at lists.maptools.org>
> Oggetto: Re: [Cartoweb-users] trouble between ajax and sent header
> Data: 14/04/08 08:33
>
> >
>>
>>
>> a frozen map is usualy the result of javascript error, do you have any?
>>
>>
>>
>> >
>> > Hi,
>> > in order to download a file I've used the header way, that is :
>> >
>> >            header('Content-Description: File Transfer');
>> >            header('Content-Type: application/octet-stream');
>> >            header('Content-Disposition: attachment;
>> > filename='.basename($file));
>> >            header('Content-Transfer-Encoding: binary');
>> >            header('Expires: 0');
>> >            header('Cache-Control: must-revalidate, post-check=0,
>> > pre-check=0');
>> >            header('Pragma: public');
>> >            header('Content-Length: ' . filesize($file));
>> >
>> > the download is ok, but after chosing every button in download dialog,
> the
>> > map is totally freezed , then if I push any button external to the map,
>> > for
>> > example the rows which move the map a bit at south,north east etc, the
> map
>> > has been unfreezed.
>> >
>> > A solution could be a reload the page after saving the file, but how 
>> > can
> I
>> > perform this ?
>> > Is there a way to send the correct header after the first one ?
>> >
>> > I've used IE 6.0.
>> >
>> > THanks in advace
>> >
>> > Please, help it's urgent
>> >
>> >
>> >
>> > --
>> > Email.it, the professional e-mail, gratis per te: http://www.email.it/f
>> >
>> > Sponsor:
>> > Scopri le tue passioni con Leonardo.it!
>> >
>> > Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=7653&d=20080413
>> >
>> >
>> > _______________________________________________
>> > Cartoweb-users mailing list
>> > Cartoweb-users at lists.maptools.org
>> > http://lists.maptools.org/mailman/listinfo/cartoweb-users
>> >
>>
>>
>>
>>
> --
> Email.it, the professional e-mail, gratis per te: http://www.email.it/f
>
> Sponsor:
> Una BMW Z4 Roadster a 10?? Prova gratis su Bidplaza.it!
>
> Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=7673&d=20080414
>
>
> 



More information about the Cartoweb-users mailing list