javascript - jQuery encode blank space in ajax query string -
i'm using api has blank spaces in query string.
stationstring=kden%20ksea
in ajax query i'm using 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 console looks this:
stationstring:kden%2520ksea
when set station variable this:
var station ="kden ksea"
my decoded url in console substitutes blank space "+".
how can pass blank space in string?
you need decode string before sending in request not double-encoded jquery's $.ajax()
method. 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) { // returned data... } });
Comments
Post a Comment