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

193
Vistas
AJAX POST request using JQuery with body and URL parameters

I'm learning how to make AJAX calls with JQuery and one thing I was wondering if it's possible to do is include some data as URL parameters and other data in the post body. For example, I'd like to do something like this:

$.ajax({
  url: '/myURL',
  type: 'POST',
  data: JSON.stringify(data),
  contentType: 'application/json; charset=utf-8'
})

but in addition to the JSON data which is being sent in the POST request body, I'd like to include URL parameters. Is there a way to do this?

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

0

You would be able to include the variables in the url portion of your code. For example

var example1 = "some_information";

$.ajax({
  url: '/myURL',
  type: 'POST',
  data: JSON.stringify(data),
  contentType: 'application/json; charset=utf-8'
})

would become

var example1 = "some_information";

$.ajax({
  url: '/myURL?var1=example1',
  type: 'POST',
  data: JSON.stringify(data),
  contentType: 'application/json; charset=utf-8'
})

You may need to put quotes around the example1 variable to ensure it doesn't break when there are spaces in the url.

about 4 years ago · Santiago Trujillo Denunciar

0

You can send parameters normally in the URL as in the get request either using ? and &

$.ajax({
  url: '/myURL?data2=' + data2 + '&data3=' + data3,
  type: 'POST',
  data: JSON.stringify(data),
  contentType: 'application/json; charset=utf-8'
})

or by set them between /

$.ajax({
 url: '/myURL/' + data2 + '/' + data3,
 type: 'POST',
 data: JSON.stringify(data),
 contentType: 'application/json; charset=utf-8'
})

The way of including the parameters on the URL will depends of the way you receive/parse them on the server side, however this is not considered as good practice for the post request.

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