cancel
Showing results for 
Search instead for 
Did you mean: 

$.request.parameters.get('key') does not accept '+' in string

Former Member
0 Kudos

Hi,

I try to call an XSJS Service with a mobile number as an parameter.

******.xsjs?cmd=read&key='(+49) 123 456 7890'

In the job the + sign is removed.

Here ist my code.

var aCmd = $.request.parameters.get('cmd');
switch (aCmd) {
    case "read":
        var key2 = $.request.parameters.get('key');
        read(key2);
        break;
    default:
        $.response.status = $.net.http.BAD_REQUEST;
        $.response.setBody('Invalid Command');
}

Any hints, what to do ?

Thanks Klaus

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor

You have to encode the value you are passing to the parameter. If your client calling the service is a JS client, you can use the function encodeURIComponent. On server side in the xsjs coding, you can use function decodeURIComponent to get the original value.

Regards,
Florian

Former Member
0 Kudos

Hello Florian,

I tried it in this way, but I received the same result.

        var key2 = decodeURIComponent($.request.parameters.get('key'));

Regards Klaus

pfefferf
Active Contributor
0 Kudos

Did the sender encode the value?

Former Member
0 Kudos

No, I startet the service from the browser.

https://******.xsjs?cmd=read&key='(+49) 123 456 7890'

pfefferf
Active Contributor

That is the issue. As mentioned you have to encode the passed value.

Former Member
0 Kudos

Hello Florian,

that was the solution.

Thanks Klaus

Answers (0)