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

250
Views
jQuery encode blank space in ajax query string

I'm using an API which has blank spaces in the query string.

stationString=KDEN%20KSEA

In my Ajax query i'm using it like this:

var station ="KDEN%20KSEA"
$.ajax({
type: "GET",
url: 'https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=tafs&requestType=retrieve&format=xml&hoursBeforeNow=3&timeType=issue&
data: {'stationString': station},

My decoded URL in my console looks like this:

stationString:KDEN%2520KSEA

When I set my station variable like this:

var station ="KDEN KSEA"

My decoded URL in my console substitutes the blank space with a "+".

How can I pass a blank space in my string?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to decode the string before sending it in the request so that it does not get double-encoded by jQuery's $.ajax() method. To do that you can use decodeURIComponent(). Try this:

var station = decodeURIComponent("KDEN%20KSEA");
$.ajax({
    type: "GET",
    url: 'https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=tafs&requestType=retrieve&format=xml&hoursBeforeNow=3&timeType=issue',
    data: { stationString: station },
    success: function(data) {
        // do something with the returned data...
    }
});
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!