Reputation: 711
$.ajax({
url: "/api/v1/cases/annotations/" + case_id + "/" + encodeURIComponent(current_plink),
I am using encodeURIComponent to escape slash. But it does not work for me. This code convert "slash" to "%2F" but apache does not recognize it.
My php part like this :
$app->get('/cases/annotations/:case_id/:prep_name', 'authenticatePathologist', function($case_id, $prep_name) use ($app) {
If i try to send parameter which include slash, it returns page not found.
But if i try to send parameter which does not include slash, it returns OK.
Upvotes: 8
Views: 19873
Reputation: 7578
I too had a similar issue with url like:
?filters=new:item:text
where it required to escape the colons. for that I tried replacing it to format
?filters/:items/:text
but that couldn't work as the Chrome was NOT encoding the '/' value.
Tried the js [escape() method][1]
and it worked like charm.
let url = 'https://dev.test.something?filters=';
let filterString = 'new:item:text';
url = url + escape(filterString);
Output:
https://dev.test.something?filters=new%3Aitem%3Atext
Hope this finds helpful!!
Upvotes: 0
Reputation: 92521
You should encode it twice with encodeURIComponent
, i.e. encodeURIComponent(encodeURIComponent(current_plink))
. If you encode it only once, the server decodes it, and it's the same as not encoding it at all.
Upvotes: 25