我正试图从我的控制器返回一个分部,并将其放入我的div标记中,这就是我目前所拥有的:
控制器:
def query
@casts = Cast.all
if params["choice"] == 'all' then
@cast_query = @casts.where(created_at: (Time.now - 1.day)..(Time.now)).includes(:votes).order("cached_votes_score").reverse_order
else
@cast_query = Cast.includes(:votes).order("cached_votes_score").reverse_order
end
respond_to do |format|
format.html { render :partial => 'home/query' }
end end
Ajax调用:
ajax_query = function(choice){
alert(choice);
var msg = {"choice":choice};
$.ajax({
type: 'POST',
url: '/top',
dataType: 'json',
data: msg,
complete: function(data) {
alert(data);
$('#dummy').html(data);
}
});
}
我没有得到部分返回
您正在请求数据类型"json";改为尝试"html":
$.ajax({
type: 'POST',
url: '/top',
dataType: 'html',
data: msg,
complete: function(data) {
alert(data);
$('#dummy').html(data);
}
});