1

I'm currently trying to pass values using an AJAX request to a server side end point. Everything works fine until I try to pass a decimal value in the url. I understand that the . character is a reserved character in the url and am wondering how I can pass a decimal value in my AJAX request.

My current endpoint is something like this; /domain/some-url/?value1=5&value2=2.3 The above url results in a 404.

If I change value2 to a whole number or a string it works file. Example would be /domain/some-url/?value1=5&value2=2 I get a successful response from the above URL.

Is there a standard way of deal with this situation?

ralph
  • 987
  • 2
  • 11
  • 20

5 Answers5

3

No, . is not a reserved character in URLs – see https://www.rfc-editor.org/rfc/rfc3986#section-2.3 – so whether it's URL-encoded or not should make no difference.

It sounds to me like the problem is instead with the server-side script not accepting dots in that argument, but it's difficult to tell why without more details.

Community
  • 1
  • 1
deltab
  • 2,498
  • 23
  • 28
3

Your problem seems to be in your server, . is not reserved. I actually tried to use encodeURI in my browser:

> encodeURI("/domain/some-url/?value1=5&value2=2.3")
"/domain/some-url/?value1=5&value2=2.3"

The result does not change. Try it.

miguelr
  • 1,334
  • 14
  • 21
2

It's not the dot per se. Why would a dot be a reserved character in a URL? In that case you wouldn't be able to use /img/someimg.jpg etc. It must have something to do with the way your server handles the request.

To be sure, I have tested this using one of my own server side testscripts @http://testbed.nicon.nl/v8test/json.xjs?testone=0.234&test2=4.56. The script is found and working like it should, no problem with the decimals.

KooiInc
  • 119,216
  • 31
  • 141
  • 177
0

Please check .htaccess or routing script on your domain/server to allow . in params;

otherwise

/domain/some-url/?value1=5&value2=2.3

is a correct way to pass decimal value in the url;

Mudaser Ali
  • 3,989
  • 3
  • 25
  • 27
-2

try sending arguments as below in your ajax request;

data: { value1:5, value2: 2.3 }
Shahbaz Chishty
  • 482
  • 1
  • 4
  • 9