Created
April 5, 2013 12:09
-
-
Save kimsan1/5318816 to your computer and use it in GitHub Desktop.
cccchat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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