最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught ReferenceError: date is not defined - Stack Overflow

programmeradmin4浏览0评论

Hey I'm trying to create a heartbeat that will tell me when a customer is done with a session.

My controller looks like this:

def update
  @customer = Customer.find(params[:id])
  @room = Room.find(params[:room_id])
  @customer.charge(@room)
  @customer.update_attribute(finished_at: DateTime.now)
  session[:customer_id] = nil

  respond_to do |format|
    format.js
    format.htmt { redirect_to root_url }
  end
end

now in my show.html.erb file I have this:

setInterval(function(){
  $.post("/customers/<%= current_customer.id %>", {finished_at: date.now()}, function(){});
}, 5000);

now when I check my console the error I get is:

Uncaught ReferenceError: date is not defined

There might be a couple of mistakes here, anybody knows whats up?

Hey I'm trying to create a heartbeat that will tell me when a customer is done with a session.

My controller looks like this:

def update
  @customer = Customer.find(params[:id])
  @room = Room.find(params[:room_id])
  @customer.charge(@room)
  @customer.update_attribute(finished_at: DateTime.now)
  session[:customer_id] = nil

  respond_to do |format|
    format.js
    format.htmt { redirect_to root_url }
  end
end

now in my show.html.erb file I have this:

setInterval(function(){
  $.post("/customers/<%= current_customer.id %>", {finished_at: date.now()}, function(){});
}, 5000);

now when I check my console the error I get is:

Uncaught ReferenceError: date is not defined

There might be a couple of mistakes here, anybody knows whats up?

Share Improve this question asked Sep 14, 2015 at 11:46 Sebastian Jennings AlmnesSebastian Jennings Almnes 1,6082 gold badges20 silver badges33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 16

date is not the valid syntax.

Use Date not date, note the uppercase D

Date.now()

Docs

发布评论

评论列表(0)

  1. 暂无评论