I am using ruby on rails at back & javascript on front end to communicate. I am using $.post() / $.getJSON & both of these calls are happening twice ! I am seeing logs of two different calls in server & if I print something in callback function , its printed twice as well.
I am pretty sure its nothing due to my code as even simplistic request function too is showing the same problem.
Could someone help ?
EDIT: Here is sample code which causes problem: controller action:
def index
@cars = Car.find(:all, :conditions => ['name like?', "#{params[:term]}%"])
respond_to do |format|
format.json { render :json => @cars.to_json (:only => [:id, :name])}
end
end
JSON call
$.getJSON("/cars", req, function(data) {
//create array for response objects
var suggestions = [];
//process response
$.each(data, function(i, val){
suggestions.push(val.name);
});
//pass array to callback
add(suggestions);
});