Skip to content

Instantly share code, notes, and snippets.

@Pepan
Created August 13, 2013 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pepan/6222083 to your computer and use it in GitHub Desktop.
Save Pepan/6222083 to your computer and use it in GitHub Desktop.
simple VLT messages - code in coffeescript: sending messages to server and receive responses, both in JSON
$(document).ready ->
tester = $('nav#tester')
if tester.length > 0
tester.find('a').click (event) ->
$('<div/>',{'class': 'query', html: JSON.stringify($(this).data('json'))}).appendTo('div#tester_commands')
$('div#tester_commands').scrollTop(1000)
$.ajax
dataType: 'json',
url: $(this).attr('href'),
type: $(this).attr('data-method').toUpperCase(),
data: $(this).data('json'),
success: (data, textStatus, jqXHR) ->
if data.id
$('nav#tester > ul > li > a').each ->
$(this).attr('href', $(this).attr('href').replace('0', data.id.toString()) )
$(this).data('json').id = data.id.toString() if $(this).data('json').id == 0
$(this).parent().css('visibility', 'visible')
$('<div/>',{'class': 'response', html: JSON.stringify(data)}).appendTo('div#tester_commands')
$('div#tester_commands').scrollTop(1000)
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment