-1
我想下面的事情發生:使用JSON對象範圍的
當我選擇一個選擇框,我希望它通過AJAX發送JSON對象到我的控制器像這樣:
var encoded = $.param(data);
jQuery.ajax ({
url: '/trips',
type: 'GET',
data: {'toSearch' : encoded},
success: function (response) {
//succes
console.log(encoded);
}
});
並使用這些作爲我的查詢參數
respond_to :json, :html
def index
@trips = Trip.scoped
@trips.where("category_id = ?", params[:category_ids]) if params[:category_ids] # category_ids = array; select * from trips where category_id IN [1,3,4]
respond_with @trips
end
我該怎麼做?什麼是序列化我的JSON對象的最佳方式是什麼?
非常感謝你,這解決了我的問題! –
我沒有足夠的聲望來做到這一點。 –