views:

33

answers:

1

I am using the typeWatch plugin to monitor a text field and I want to send a callback to a controller to then replace a divin the view. The event is hitting the controller but I cannot seem to get the div to update the contents:

$(function() {
  $("#start_date").typeWatch( { highlight: true, callback: finished } );
    function finished(date) {
  $.post('/matches/watch', {
      'date': date,
      complete: function(request){
        $('#watch').effect('highlight', {color: "#C3FF29"}, 2000);
      },
    });
  }
});

#match_controller

def watch
  @preview_start_date = params[:date]
  respond_to do |format|
    format.js
  end
end

#watch.html.js

$("#watch").html(<%= @preview_start_date %>);

Any help?

+1  A: 

Try this:

$("#watch").html('<%= @preview_start_date %>');

And also indicate to jQuery that you will be returning javascript from your controller:

$.post(
    '/matches/watch', 
    { 'date': date },
    function(request) {
        $('#watch').effect('highlight', {color: "#C3FF29"}, 2000);
    },
    'script'
);
Darin Dimitrov
thanks that was what was missing!
Cameron