Skip to Content
0

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

Jun 13, 2017 at 09:10 AM

80

avatar image
Former Member

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

xsjs-debugging.jpg (91.3 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Florian Pfeffer
Jun 13, 2017 at 09:46 AM
1

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

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hello Florian,

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

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

Regards Klaus

0

Did the sender encode the value?

0
Former Member

No, I startet the service from the browser.

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

0

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

1
Former Member

Hello Florian,

that was the solution.

Thanks Klaus

0