0

I´m programming a call with axios.get with an url that is similar to:

http://example.com/path?element1={example1}&element2={example2}&element3={function(query)}

function ((condition1: string, condition2: string) => {
  query = "";
  if(condition1 is x){
    query = "&condition1" + condition1;
  }
  if(condition2 is x){
    query = "&condition2" + condition2;
  }
)

If the value in condition1 or in condition2 is something like: "bananas" it works perfectly.

But the problem is that if the value in condition1 or in condition2 is something like "bananas & potatoes"

Whe it comes to the back end its something like:

condition1: {"bananas ", " potatoes"}

instead of

condition1: "bananas & potatoes"

If you know why this can be happening or what am i doing bad please let me now.

Thank you.

  • Does this answer your question? [Escaping ampersand in URL](https://stackoverflow.com/questions/16622504/escaping-ampersand-in-url) – Rashomon Feb 25 '22 at 12:17

1 Answers1

0

You'll need to URI encode the condition:

encodeURIComponent('bananas & potatoes')

Your backend may then need to decode this. If you're using node:

decodeURIComponent(condition)
Jamie
  • 3,105
  • 1
  • 25
  • 35