0

I make an ajax call to populate dynamically a select tag on user's option.

function updateSelect(){
    var ddlTool = $('#selectTool');
    var ddlAction = $('#selectAction');
        ddlTool.on('change',function(){ 
            //append the placeholder
            ddlAction.html('<option value="NONE">Select action</option>')
            var option = ddlTool.val();
            $.ajax({            
                url: "/eMuse/loadActions",
                    data : {id:option}, 
                success : function (response){
                    debugger;
                    for(var i = 0; i < response.length; i++){
                        ddlAction.append('option value="' + response[i].value + '">'+
                                response[i].text + '</option>');
                    }
                }
            });
    });
}

In Controller i have this method:

    @RequestMapping(value = "/loadActions", method = RequestMethod.GET, produces ="application/json")
    public @ResponseBody List<DropDownListItem> loadActionsGET(@RequestParam("id") long id) {

        // load actions by selected tool
        List<ActionViewModel> actions = StudentModelMapper
                .mapListActionDTOToListActionVM(actionService
                        .getActionsByIdTool(id));
        List<DropDownListItem> items = new ArrayList<DropDownListItem>();
        for (ActionViewModel a : actions) {
            items.add(new DropDownListItem(String.valueOf(a.getIdAction()), a
                    .getName()));
        }

        return items;

    }

If i run :

http://localhost:8080/eMuse/loadActions?id=1 i also get the NOT FOUND error

In my web.xml file i have map the servlet like this:

<servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

If i replace the url-pattern *.html with /* then I am able to run the link above, but everything else falls apart.

Can anybody help me?

laura
  • 2,085
  • 13
  • 36
  • 68

1 Answers1

0

You have set the request mapping to be /loadActions

However you have told spring to only be responsible for urls with this pattern :

<url-pattern>*.html</url-pattern>

You probably want to change the url pattern, to /*, or change that specific request mapping to /loadActions.html

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • If I change the request mapping to /loadActions.html i get NOT ACCEPTABLE error. The link generated by jquery is `http://localhost:8080/eMuse/loadActions.html?id=1` – laura Mar 24 '15 at 13:43
  • I am not sure i understand what you mean. – laura Mar 24 '15 at 14:06
  • @laura http://stackoverflow.com/questions/11065252/what-is-the-point-of-jquery-ajax-accepts-attrib-does-it-actually-do-anything – NimChimpsky Mar 24 '15 at 14:07
  • I made the changes you suggested. I don't understand why if I change the url pattern to `/*` I get error 404 on each page i run – laura Mar 24 '15 at 14:20