[OpenLayers-Users] OpenLayers.Request.GET doesn't get data

Eric Lemoine eric.lemoine at camptocamp.com
Wed Sep 23 00:47:20 EDT 2009


On Tuesday, September 22, 2009, Tobias Wendorff
<tobias.wendorff at uni-dortmund.de> wrote:
> Hi there,
>
> how can I make OpenLayers.Request.GET work?
>
> I've changes this in the example-file "click.html":
>
> trigger: function(e) {
>      var lonlat = map.getLonLatFromViewPortPx(e.xy);
>      var request = OpenLayers.Request.GET({
>          url: 'http://127.0.0.1/coordinates.php',
>          params: {get: lonlat}
>      });
>      alert(request.responseText);
> }
>
> "coordinates.php" looks like this:
>
> <?php
> header('content-type: text/plain');
> echo $_GET['get'];
> ?>
>
> The PHP-script works without a problem, but the messagebox
> of OpenLayers is empty. What's wrong here?

You need to pass the GET function a callback:

OpenLayers.Request.GET({
    url: "url",
    params: {
        get: "get"
    },
    success: function(request) {
        alert(request.responseText);
    }
});

Look at the API docs, you can also pass "failure" and "callbacks"
functions. You use the latter when you yourself want to determine
error conditions.

Cheers,
>
> Best regards,
> Tobias
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>

-- 
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 Users mailing list