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
Вопрос
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