I'm not using GSP files and I'm getting nulls on my params.data to return back to my application as JSON. My problem is on the grails or javascript?

javascript

var data = $('input:checkbox[name=grid-checkbox]:checked').map(function() { return $(this).val(); }).toArray();
$.ajax({
    type: "GET",
    data: data,
    crossdomain: true,
    url: "http://..../food",
    success: success,
    error: fail
});

grails

def food() {
    def result = []
    def checkbox = params.data
    def b
    println params.data //null
    checkbox.each {
        b = Food.findAllById(checkbox.it).collect { Food food ->
            result << [id: food.id,
                    foodType: food.foodType
            ]
        }
    }
    return formatAndRender("JSON", params.callback, result)
}
有帮助吗?

解决方案

Your data is null because no data key exists in the params map.

data: data should be a valid key value pair like

data: "data=" + data
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top