0

I have a web app where if someone selects something in the dropdown menu, it changes the next field with Ajax. I'm having difficulty when the values of the dropdown have a '+' symbol which breaks it.

For example this works:

if ($_GET['ch'] == 'Something here - here') {}

However this does not

if ($_GET['ch'] == 'Something here + here') {}

I'd like a solution to be able to include the + symbol inside. Some symbols seem to work fine including brackets (), dashes -, etc.

Jimmy
  • 23
  • 4

1 Answers1

0

Try encodeURI function, and/or use POST instead.
Also escaping characters would be good. (like \+ instead of +)
When you are escaping characters than at php side you should use stripslashes function if you need special characters.

J K
  • 632
  • 7
  • 24
  • According to [this](https://stackoverflow.com/questions/1373414/ajax-post-and-plus-sign-how-to-encode?noredirect=1&lq=1) answer, there is no need to decode in PHP as it is already decoded when you use `$_GET`, `$_POST` and `$_REQUEST`. – Script47 Feb 20 '18 at 16:18
  • @Script47 Sorry for mistake, just fixed it. – J K Feb 20 '18 at 16:22