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?
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...
}
});