[OpenLayers-Dev] asynchronous cross domain POST request inside openlayers

Eric Lemoine eric.lemoine at camptocamp.com
Sun Apr 5 17:48:56 EDT 2009


On Tue, Mar 31, 2009 at 5:30 PM, loic devaux <devloic at gmail.com> wrote:
>
> Hi List,
>
> I am implementing a new OpenLayers layer type ( using existing WMS layer code) to display data from CartoWeb (3.5) Web-GIS with OpenLayers. Because CartoWeb's architecture can be divided in two servers ( one dealing with the user interface and another dealing with the GIS processes) I need to make a cross browser POST request to fetch data but that's not possible with Xmlhttprequest . I don't want to user OpenLayers Proxyhost capability because that will increase traffic and complexity for deployment.
> There are some solutions with GET requests but the one that works fine for me for POST requests is submitting a dynamically generated form inside a dynamic iframe. I read Google Maps has something similar.
> Now my problem is that I rely on the onLoad event of the iframe that tells me when the fetched data is available in the browser. Because this is an asynchronous execution I haven't found a way to feed OpenLayers with the data because there is no way (?) in javascript ( without doing ugly cpu intensive javascript loops or waiting for javascript 1.7 ) to halt execution and resume it once the callback function (which retrieves the data) associated to the onLoad event of my iframe has been triggered.
> I managed however to make things work for the layerswitcher control but the other openlayers controls are far more complex and  I try to be the less intrusive as possible so I don't want to modify the source code of each control (which wouldn't be a solution for custom controls anyway).
> The only solution I see would be to be able to specify the execution order of the callbacks so I could execute my callback first which woud :
> - store the event context
> - stop the other callbacks from executing
> - fetch the CartoWeb data
> - recall the stopped callbacks using the stored context
>
> I don't know if this is feasible as it seems that each browser might handle the execution order of browser events differently but maybe OpenLayers has more control on his own events.
>
> Sorry for the necessary verbosity. I'd be glad to see alternative solutions. I believe that by solving this problem we would at the same time extend OpenLayers interoperability since cross domain requests inside the browser might more and more belong to the future of the web even though this raises legitimate security concerns.
>
> Loïc

Hi Loïc

Just a quick comment. I fail to see why you need synchronous behavior
here, e.g. why would the LayerSwitcher need to know when the data has
been received?

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com



More information about the Dev mailing list