문제

I am using a jQuery ajax command, which has the following data:

$.ajax({
type:"POST",
 ...
 data:"e=f_s&es="+JSON.stringify(email)+"&fr="+str
 ...
})

Where (email) can contain special character, for example it can be a string:

!#$%'&+-/=?^`*{|}~ch!#$%'/=?*^`{|}@mail.com

The reason why I allow such characters, is based on the following question.

The problem is, at some point on the server (Java EE application), it is messing up. The special characters are not showing the boundaries of different request parameters. For example it is considering :

'/

as a parameter.
I think I need to escape characters? (if yes how?)

What should I do to be able to send such a string from javascript to java ?

도움이 되었습니까?

해결책

Use encodeURIComponent:

encodeURIComponent("!#$%'&+-/=?^`*{|}~ch!#$%'/=?*^`{|}@mail.com")

returning:

"!%23%24%25'%26%2B-%2F%3D%3F%5E%60*%7B%7C%7D~ch!%23%24%25'%2F%3D%3F*%5E%60%7B%7C%7D%40mail.com"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top