Skip to content
Advertisement

PHP not comparing “#”

I have a simple script where I enter some text on my search bar and PHP echo the first character from the text.

My code:

JavaScript

Here everything is working fine but the # is neither being compared nor being echo. It just shows blank. I tried to convert it into a string using strval() but it’s not working too! What should I do?

my ajax call from jquery:

JavaScript

Advertisement

Answer

Actually, # is a fragment that is not sent to the server and also the part coming after it. So you will never get # by $_GET['u'], until you decode it.
Since the UPDATE you can control the querystring. So encode query in Client side (JS). Then decode it in Server side (PHP) back.
JS:

JavaScript

PHP:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement