Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
¿Cómo hago una solicitud $.get usando coffeescript?

¿Cómo hago lo siguiente en 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 answers
Answer question

0

Aquí hay otra forma ligeramente condensada de escribirlo:

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

Tenga en cuenta la falta de paréntesis y el literal de objeto abreviado "{username}".

over 4 years ago · Santiago Trujillo Report

0

Este es el mejor patrón genérico que he encontrado hasta ahora:

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

Se compila hasta:

 $.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 Report

0

Esta es una manera:

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

Algunos de estos paréntesis se pueden omitir, pero en mi opinión, ayudan a comprender el flujo del código (al menos en esta situación).

Recomiendo jugar con coffeescript aquí http://jashkenas.github.com/coffee-script/ (use el botón "probar coffeescript"). El idioma es muy fácil de aprender.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!