[OpenLayers-Dev] Sending the "X-Requested-With" header in AJAX calls

Eric Lemoine eric.lemoine at camptocamp.com
Wed Sep 7 03:08:21 EDT 2011


On Wed, Sep 7, 2011 at 8:47 AM, Marc Jansen <jansen at terrestris.de> wrote:
> Hi all,
>
> Should we send the X-Requested-With header [1] in AJAX calls as many
> other libraries do? Most libraries include this non-standardized header
> to show the server that the request is an AJAX-call.
>
> In my particluar case a symfony backend would send different output
> depending on whether an URL is retrieved via AJAX or the usual way.
>
> I can provide a patch if that is desired, something roughly looking like
> this:
>
> Index: lib/openlayers/trunk/lib/OpenLayers/Request/XMLHttpRequest.js
> ===================================================================
> --- lib/openlayers/trunk/lib/OpenLayers/Request/XMLHttpRequest.js
> (revision 12333)
> +++ lib/openlayers/trunk/lib/OpenLayers/Request/XMLHttpRequest.js
> (working copy)
> @@ -217,6 +217,9 @@
>         }
>     };
>     function fXMLHttpRequest_send(oRequest) {
> +        // always set the X-Requested-With:-header
> +        oRequest._object.setRequestHeader("X-Requested-With",
> "XMLHttpRequest");
> +
>         oRequest._object.send(oRequest._data);
>
>         // BUGFIX: Gecko - missing readystatechange calls in
> synchronous requests

Sounds good to me.



-- 
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