[Dancer-users] Problem with Dancer::Plugin::Ajax under Plack

Gurunandan Bhat gbhat at pobox.com
Mon Jan 30 06:14:57 CET 2012

It does. Thanks.

On Mon, Jan 30, 2012 at 3:43 AM, Oliver Gorwits <oliver at cpan.org> wrote:
>> Unfortunately, the "ajax" route is not recognised and it gives me a 404
>> However I find that when I add
>> Dancer::Handler->init_request_headers($env); in the sub, the Ajax
>> route works fine. Dancer::Handler docs are not available and I need to
>> understand why this works
>> Would appreciate if someone could explain
> Routes configured with the Ajax Plugin's "ajax" helper will only match
> when the "X-Requested-With" HTTP Header is present and has the value
> "XMLHttpRequest" (i.e. it's an AJAX request).
> You can see this in the app's console log... the route appears to be found
> successfully but then is  rejected because of the missing X-Requested-With
> HTTP Header. Another way to see the problem is to configure a 'before'
> hook sub which calls Data::Dumper::Dumper on Dancer's request() object -
> you'll see the HTTP Headers value is undef.
> By adding the init_request_headers() call you're fixing this problem, and
> the Headers are correctly parsed and made available to Dancer's request
> object, so your route is now accepted.
> I hope that makes sense,
> regards,
> oliver.

More information about the Dancer-users mailing list