我沒有使用GSP
文件,而我的params.data
上的空值沒有回到我的申請JSON
。我的問題是關於grails或javascript?沒有GSP的Grails處理複選框
的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)
}
看起來是與你的jQuery的問題。在你的ajax調用中嘗試data {data:data}。 –
當我的互聯網啓動時我會盡快檢查 – fsi
請小心,我有一個小錯字,它應該是數據:{data:data} –