0

I am receiving a json response to construct a parameterized string in JavaScript. However I need to pass actual parameters from JavaScript on some properties e.g. custom_input has to change dynamically.

[{ "road_name_gr": "custom_input" "town_code" : 1 }]

Then I read that json file and convert that to a url.

cql_filter = new URLSearchParams(json_file).toString();  

output: town_code=1&road_name_gr=custom_input

However I have to "modify" the url to accept input.

e.g. 'town_code=1&road_name_gr=' + my_custom_input

1 Answer 1

1

Try this:

my_custom_input = decodeURIComponent(my_custom_input) // URI Decode
let input_params = new URLSearchParams(json_file);
input_params.set("road_name_gr", my_custom_input);
cql_filter = input_params.toString();

You have to set parameter before obtain string value.

Sign up to request clarification or add additional context in comments.

3 Comments

my_custom_input is in greek. I get : town_code=1&road_name_gr=%CE%A3%CE%91%CE%A1%CE%91%CE%A3 . Also it should not set, it should replace.
The set method overwrites existing field.
Try this: my_custom_input = decodeURIComponent(my_custom_input) on top of block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.