Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda