0

I am trying to do a call to url

http://example.com/controller/action?var1=CD14+%20MDM%20in%20GM-CSF%203%20days%20then%203%20days%20IFN-%CE%B3&var2=56&var3=ENSG00000115415

If you look at var1 that I am passing value 'CD14+ MDM in GM-CSF 3 days then 3days IFN-γ'.

When in the controller I try to get this var 1 using request.params.get("var1"), i get 'CD14 MDM in GM-CSF 3 days then 3days IFN-γ' with missing + and instead getting extra space after CD14

How can I pass + in my variable in url

mgilson
  • 300,191
  • 65
  • 633
  • 696
isha
  • 1

3 Answers3

0

This has an answer here. It says that + needs to be encoded as %2B.

Community
  • 1
  • 1
JD Hernandez
  • 1,785
  • 1
  • 20
  • 29
0

If you are intended to use plus as a data component, instead of url component, You should pass %2B instead.

Javascript :

var url = "http://example.com/controller/action?var1=CD14+%20MDM%20in%20GM-CSF%203%20days%20then%203%20days%20IFN-%CE%B3&var2=56&var3=ENSG00000115415";

//NOTE: this following wil lreplace all + to %2B
url = url.replace(/\+/g,"%2B");

console.log("new : ",url);
Jimish Fotariya
  • 1,004
  • 8
  • 21
0

Try '%2B' (as other have stated).

But if you are in Javascript, you could just use the built-in method for doing URL encoding called "encodeURIComponent". Note you need that and not "encodeURI" which will not encode reserved characters like '+'. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent