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

84
Views
typeahed realiza una llamada ajax solo si la cadena contiene espacio

Estoy tratando de usar/configurar la escritura anticipada para realizar la llamada ajax si la cadena escrita contiene espacio. Para ser más específico, me gustaría mostrar direcciones completas pero en mi API me gustaría evitar la parte del número de calle. Estaba tratando de lograr eso usando una función asignada a la propiedad 'fuente':

 $("#select").typeahead({ minLength: 3, source: function (request, response) { var streetName = ''; for (i = 1; i < streetParts.length; i++) { streetName += streetParts[i] + ' '; } if (streetName.length < 3) return null; $.ajax({ url: "/api/Search/suggest/", data: { "input": streetName.trim() }, type: "GET", hint: true, contentType: "json", success: function (data) { items = []; map = {}; $.each(data, function (i, item) { var id = item.document.id; var name = item.text; map[name] = { id: id, name: name }; items.push(name); }); response(items); }, error: function (response) { alert(response.responseText); }, failure: function (response) { alert(response.responseText); } }); }, updater: function (item) { //If simultaneously want to update value somewhere else $("#selected").html(map[item].id); return item; } });

aunque puedo ver que la solicitud en la pestaña de red está bien, el div con los resultados no se procesa. Si elimino la declaración if de la función fuente, funciona bien. ¿Es la forma correcta de cancelar la ejecución de la función fuente (devolviendo nulo)? ¿Hay alguna otra propiedad o forma de lograr lo que estoy intentando?

about 4 years ago · Juan Pablo Isaza
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!