Created
August 13, 2013 15:01
-
-
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
This file contains 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
$(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