emilan
emilan

Reputation: 13065

Access plugin controller from js

I want to create a plugin. In my plugin I must call controller action from my function. Below is the snippet of ajax call, which is in separate js file.

    $.ajax({
            type:'POST',
            url:"/wf-taglibs/refTagLib/getDescriptionByCode",
            data:{
                'code':code,
                'beanClass':beanClassAttribute
            },

            success:function (data) {
                $('#' + updateFieldAttribute).text(data);
            },
            error:function (xhr, ajaxOptions, thrownError){
                alert(xhr.status);
                alert(thrownError);
            }
        });

I've got problem with url. url:"/wf-taglibs/refTagLib/getDescriptionByCode", As response we get 'the requested page not found'.

Upvotes: 4

Views: 169

Answers (1)

Sudhir N
Sudhir N

Reputation: 4096

I wouldn't hard code URLs like this, but rather declare a js variable inside of my gsp that points to the right controller/action and then have my js code use that variable.

var getDescriptionEndpoint = "${createLink(controller:'x', action:'x')}";

And then use that variable in the js code that makes ajax calls. That way it will consider reverse url mappings as well.

Though its not a good idea, but if you want to declare your variables directly into js file - in otherwords - if you want to treat your js files as gsp - see gsp-arse plugin

Upvotes: 2

Related Questions