I’m doing an ajax request through jQuery and for example, my URL is http://test.com/query.php?hello=foo bar
However, the request only takes http://test.com/query.php?hello=foo. How do I make it so it takes even spaces? And special character entities like &, -, !, etc.
Thanks
By properly url encoding the space:
or:
It’s the same. Make sure you url encode them properly:
&=>%26-=>-(doesn’t need to be encoded)!=>!(doesn’t need to be encoded)In order to properly do this in javascript you could use the
encodeURIComponentfunction.Or if you use jQuery you could also take a look at the
$.param()method.Finally if you are sending an AJAX request using jQuery you could do this:
and jQuery will take care of properly url encoding the query string parameter passed in the
datahash.