Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.