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

190
Views
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 answers
Answer question

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 Report

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 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!