Frage

I'm trying to return a partial from my controller and put it in my div tag this is what i have so far:

Controller:

  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 Call:

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);

    }
});
}

I'm not getting the partial back

War es hilfreich?

Lösung

You're requesting the datatype 'json'; try 'html' instead:

$.ajax({
    type: 'POST',
    url: '/top',
    dataType: 'html',
    data: msg,
complete: function(data) {
    alert(data);

    $('#dummy').html(data);

    }
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top