Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
how do i make a $.get request using coffeescript?

How do I do the following in CoffeeScript?

  $( function() {
    $('input#username').keyup( function() {
      var username = $('input#username').val();
      url = '/users/check_username/';
      params = { username : username };
      $.get(url, params, function(response){ markUsername(response); }, "json");
    });
  })
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Here's another slightly condensed way to write it:

$ ->
  $('input#username').keyup ->
    username = $(this).val()
    callback = (response) -> markerUsername response
    $.get '/users/check_username/', {username}, callback, 'json'

Note the lack of parens, and the shorthand "{username}" object literal.

over 4 years ago · Santiago Trujillo Relatório

0

This is the best generic pattern I've come up with so far:

$.ajax '/yourUrlHere',
  data :
    key : 'value'
  success  : (res, status, xhr) ->
  error    : (xhr, status, err) ->
  complete : (xhr, status) ->

It compiles down to:

$.ajax('/yourUrlHere', {
  data: {
    key: 'value'
  },
  success: function(res, status, xhr) {},
  error: function(xhr, status, err) {},
  complete: function(xhr, status) {}
});
over 4 years ago · Santiago Trujillo Relatório

0

This is a way:

$(->
    $('input#username').keyup(->
        username = $('input#username').val()
        url = '/users/check_username/'
        params = {username: username}
        $.get(url, params, (response)->
            markerUsername(response)
        , "json")
    )
)

Some of these parenthesis can be omitted, but in my opinion, they help with understanding the code flow (at least in this situation).

I recommend fiddling around with coffeescript here http://jashkenas.github.com/coffee-script/ (use the "try coffeescript") button. The language is very easy to learn.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda