Javascript函数调用未在Grails控制器中调用正确的withFormat选项

时间:2014-07-31 16:35:07

标签: javascript grails

我从Javascript调用Grails控制器中的方法。我使用的是Grails 2.3.9。

function renderCalendar() {
    $("#calendar").fullCalendar({
        events: '/calendar/list',
        contentType: 'json',
        type: 'POST',
        header: {...

控制器中的代码是:

withFormat {
    html {
        [calendarInstanceList: eventList]
    }
    json {
        render eventList as JSON
    }
}

但是,不执行request.withFormat的json闭包。不知道为什么。

另外,我在Javascript中试过这个:

function renderCalendar() {
    $("#calendar").fullCalendar({
        events: '/calendar/list.json',
        contentType: 'json',
        type: 'POST',
        header: {...

并且这不会调用有问题的控制器。

我还尝试了几个contentType参数:

contentType: "text/json",
...
contentType: "JSON_CONTENT_TYPE",
...
contentType: "text/json",

我还在Config.groovy中启用了mime标头:

grails.mime.use.accept.header = false

以下是我的Config.groovy中的mime类型:

grails.mime.types = [html: ['text/html', 'application/xhtml+xml'],
        xml: ['text/xml', 'application/xml'],
        text: 'text/plain',
        js: 'text/javascript',
        rss: 'application/rss+xml',
        atom: 'application/atom+xml',
        css: 'text/css',
        csv: 'text/csv',
        pdf: 'application/pdf',
        excel: 'application/vnd.ms-excel',
        rtf: 'application/rtf',
        ods: 'application/vnd.oasis.opendocument.spreadsheet',
        all: '*/*',
        json: ['application/json', 'text/json'],
        form: 'application/x-www-form-urlencoded',
        multipartForm: 'multipart/form-data'

0 个答案:

没有答案