AngularJS cyrillic characters and get params - angularjs

When i try to send cyrillic characters as get params
They are transformed into that
What am I doing wrong?

That's normal, use decodeURIComponent() to decode the url paramaters
http://www.w3schools.com/jsref/jsref_decodeuricomponent.asp

Related

React routes param auto decode string

Hi does react router params automatically decodes string?
For example i have this route
<Route path="/callback/:url"/>
and when I call it with C5jb20%3D
it will print C5jb20= when I console.log() that parameters
Is this an expected behavior? Can I change this behavior so that I still get the encoded string?
Thanks!
C5jb20%3D is a URL encoded string, which is a way to encode special characters in a URL. For example, if you have a URL parameter like ?redirect=/some/path, a server could interpret the forward slashes as routing paths, and mess up the expected routing. That's why you see things like ?redirect=%2Fsome%2Fpath, and your example, in URLs.
window.location.path will have the original, unencoded URL.
You could also get it back with encodeURIComponent:
encodeURIComponent('C5jb20=') // "C5jb20%3D"
You probably don't want to, though, depending on your use case.

Angular ui-router - Curly brackets etc in url

I have been searching for a way to have curly brackets{} and slashes / in the URL. But the URL looks like this:
URL appearance now:
http://localhost/#/?ph=tes:testes%2Ftest%7Blb0%7D
URL wanted appearance:
http://localhost/#/?ph=tes:tests/test{lb0}
How do I get an URL without the %2f etc?
Thanks in advance!
All valid characters that can be used in a URI (a URL is a type of URI) are defined in RFC 3986.
All other characters can be used in a URL provided that they are "URL Encoded" first. This involves changing the invalid character for specific "codes" (usually in the form of the percent symbol (%) followed by a hexadecimal number).
This link, HTML URL Encoding Reference, contains a list of the encodings for invalid characters.
Happy Helping!
These (%2F, %7B) are escape sequences. They represent the special characters that are in your URL, as a URL cannot contain these character directly.
Where do you want exactly to process this URL?
You can use Javascript's unescape(url) to get the escaped URL string back to the original one if you're going to process it in Javascript itself.

angularjs $http : sending special characters in path param

I am trying to invoke a REST service which has a special character in its path params. The rest url looks like,
rest\fetchDetails\[1,2,3]
I am just invoking it using $http like,
$http.get('rest\fetchDetails\[1,2,3]');
It is not working and when I debug it using firebug I can see the url is sent as
rest\fetchDetails\%5B1,2,3%5D
Is there any way to send '[' and ']' when invoking $http calls?
Solution 1:
Try with post request and pass params in Post Request.
Solution 2:
'[]' are special characters for URL. So it will be encoded.
If you want to decode this are your server code you can do it.
You are actually sending '[' and ']', however they are being url-encoded by the $http.get method. The url-encoding is necessary because the HTTP standard only allows some characters (alpha-numeric plus some) to be sent non-url-encoded.
BTW, I assume the backslashes () in your URL are regular slashes (/) since otherwise they too would be url-encoded.

angualrjs: escape slashes from parameter value passed to $http.get

I am using a simple HTTP GET call in angularjs and passing some query string parameters.
One of the param is a date. Let's say "update" and the value passed is 03/20/2015.
When I make $http.get call passing the "update" as query string parameter,
the request is sent as
http://myservice.com/services/products?update=03%2F20%2F2015
I would like to send it as
http://myservice.com/services/products?update=03/20/2015
Any help is greatly appreciated.
I suggest to replace slashes with dashes in the date: 03-20-2015
here you can find some more informations
%2F is just the encoded url for '/', your back-end could decode it automatically.

Saving new Lines in database and Json

I have this problem:
I have an HTML textarea which is filled by the user. (And he can press The enter button to go on a new line).
Then I take The value of The textarea using the command:
document.getElementById("textareaCommento")
And I pass The value to the servlet using an XmlHttpRequest.
In The servlet I save this value in a database.
Since this point I have no problems...
Then, in another part I want to get The values from The database. Using a servlet I make this query
Select * from comments
And I transform the results in json. Here I have The problem... The newline character makes my JSON string invalid. For example:
"Comment":"hello
Word"
How can I do?
Thanks in advance!
You have to replace the \n character from database to something like <br/>
For the replace see replace \n and \r\n with <br /> in java
this CSS worked for me,
white-space: pre-line;
You should be able to url encode your values so hello world would actually become "hello%20world", to do it in java see here:
Encoding URL query parameters in Java
To do it in javascript see here:
Encode URL in JavaScript?

Resources