Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
JQuery AJAX URL Rest path parameters

I have a Rest service on /users/{userId}/orders/{orderId} (please note the path parameters) and I want to call it from JQuery.

I could do it simply concatenating the ids like so:

$.get(
    'users/' + 1234 + '/orders/' + 9876,
    function (data) {
        //do something with the response
    }
);

But this doesn't seem like a very correct way of doing it (although it does the job).

Is there a better way of passing these path parameters on the URL of a JQuery AJAX call?

* just to clarify, my concern is more with the concatenation of the string. I wonder if there's a better way to construct the url without concatenating strings. Perhaps string formatting would be better?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I think Template literals is the neatest way to proceed here:

$.get(
    `users/${userId}/orders/${orderId}`,
    function (data) {
        //do something with the response
    }
);
about 4 years ago · Santiago Trujillo Denunciar

0

You can make a function to make this request :

function makeOrderRequest(userId, orderId, sucessCallback) {
    $.get('users/' + userId + '/orders/' + orderId, successCallback);
}

And then call it when you need :

makeOrderRequest(1234, 8796, function(data){
     //do stuff
});
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda