[Dancer-users] ajax method, what? why? how?

P Kishor punk.kish at gmail.com
Sat Aug 21 15:23:00 CEST 2010

I can't figure out how the ajax method works. In my JavaScript (with
jQuery), I have

        beforeSend: function(xhr){
            xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
        url: '/model/' + model_id,
        dataType: "json",
        success: function(data) {

            // do something with

and, in my App.pm, I have

    ajax '/model/:model_id' => sub {
        my $result = do something with model_id
        return to_json($result);

however, the above doesn't work at all. I get a 404. If I change the
ajax method to

    get '/model/:model_id' => sub {}

then it works fine. Which brings me to the question -- what is this
ajax method supposed to do better than get or post? And, why doesn't
it work for me?

Puneet Kishor http://www.punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
Assertions are politics; backing up assertions with evidence is science

More information about the Dancer-users mailing list