Skip to content

Instantly share code, notes, and snippets.

@kimsan1
Created April 5, 2013 12:09
Show Gist options
  • Save kimsan1/5318816 to your computer and use it in GitHub Desktop.
Save kimsan1/5318816 to your computer and use it in GitHub Desktop.
cccchat
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
jQuery ->
MessagePoller =
poll: ->
setInterval ->
MessagePoller.request("get_new": "yes")
, 1000
true
request : (data) ->
$.ajax(
type: "POST",
url: $("#messageform").attr("action")
data: data
dataType: "JSON"
).success (json) ->
# alert(json)
# $("ul#messages").append("<li>" + json+ "</li>")
#act on result.
false
$("#formsubmit").click ->
valuesToSubmit = $("textarea#message").val()
sendData = {"message" : valuesToSubmit}
$("ul#messages").append("<li>" + valuesToSubmit + "</li>")
$("textarea#message").val('')
MessagePoller.request(sendData)
false # prevents normal behaviour
MessagePoller.poll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment