开发者

Issue with javascript escape, encodeURI and encodeURIComponent

My application sends data from javascript to my servlet using ajax POST request and that data contains special characters as well. I am sending this data after executing javascript escape() over the data as my content can also contains URL's.

The problem is that I do not get correct data at my servlet end and I am suspecting that escape is creating the is开发者_如何转开发sue.

I tried following in my javascript code :

alert(escape("»"));
alert(unescape(escape("»")));

alert(encodeURI("»"));
alert(decodeURI(encodeURI("»")));

alert(encodeURIComponent("»"));
alert(decodeURIComponent(encodeURIComponent("»")));

I do not get correct alert when I am unescaping the escape string, As seen by the code, I have also tried using encodeURI, encodeURIComponent and their respective decoding methods.

How should I send the data from javascript so that all of the special character and other part of the content (like URL's) are received properly.


<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

was the issue, Changed it to UTF-8, works fine now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜