jquery - javascript ajax request in rails not able to pass values -
i have rails application in have following controller action.
def index .... .... @currency = params["currency"].present? ? params["currency"] : "inr" @check_in_date = params["arrival_date"].present? ? params["arrival_date"] : date.today.to_s @check_out_date = params["departure_date"].present? ? params["departure_date"] : (date.today + 1).to_s .... .... end
i have javascript trying make ajax request this. filename.html.haml
else{ hotel_id = id.slice(6) $.ajax({ url: "/single_hotel/"+hotel_id, data: {check_in_date: #{@check_in_date}, check_out_date: #{@check_out_date}, longitude: #{@longitude}, latitude: #{@latitude}, rooms: #{@rooms}, adults: #{@adults}, children: #{@children}, currency: #{@currency} }, type: 'get' }); }
when check sources tab in chrome console see this.
$.ajax({ url: "/single_hotel/"+hotel_id, data: {check_in_date: 2016-08-08, check_out_date: 2016-08-09, longitude: 34.854, latitude: 32.3213, rooms: 1, adults: 1, children: 0, currency: inr }, type: 'get' });
when try make ajax request "vm18204:52 uncaught referenceerror: inr not defined".
also if remove currency , make request following values check in & check out dates.
[1] pry(#<bookings::hotelscontroller>)> params => {"check_in_date"=>"2000", "check_out_date"=>"1999", "longitude"=>"34.854", "latitude"=>"32.3213", }
can please me here.
instead of this
data: {check_in_date: #{@check_in_date}, check_out_date: #{@check_out_date}, longitude: #{@longitude}, latitude: #{@latitude}, rooms: #{@rooms}, adults: #{@adults}, children: #{@children}, currency: #{@currency} }
try this
data: {check_in_date: "#{@check_in_date}", check_out_date: "#{@check_out_date}", longitude: "#{@longitude}", latitude: "#{@latitude}", rooms: "#{@rooms}", adults: "#{@adults}", children: "#{@children}", currency: "#{@currency}" }
Comments
Post a Comment