js urlencode , encodeURIComponent
js 对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent
1、 传递参数时需要使用encodeURIComponent,这样组合的url才不会被#等特殊字符截断。
例如:<script language="javascript">document.write('<a href="http://passport.baidu.com/?logout&aid=7& u='+encodeURIComponent("http://cang.baidu.com/bruce42")+'">退出</a& gt;');</script>
2、 进行url跳转时可以整体使用encodeURI
例如:Location.href="/encodeURI"("http://cang.baidu.com/do/s?word=百度&ct=21");
3、 js使用数据时可以使用escape
例如:搜藏中history纪录。
4、 escape对0-255以外的unicode值进行编码时输出%u****格式,其它情况下escape,encodeURI,encodeURIComponent编码结果相同。
最多使用的应为encodeURIComponent,它是将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果给后台传递参数需要使用encodeURIComponent时需要后台解码对utf-8支持(form中的编码方式和当前页面编码方式相同)
escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
根据说明 我需要的是encodeURIComponent函数
--------------------------------------------------------------------------------------------------------------
据上所述
1、浏览器,表单发的URL是和页面编码一致的
2、浏览器中用XMLHTTP发送的URL是和浏览器默认设置一致的
3、请求 URL 与服务器一致则无乱码出现
PS: 推荐使用 encodeURIComponent(), 用它编码过的 URL 与 PHP urlencode() 函数执行结果一致,交互最为便捷.
js urlencode , encodeURIComponent的更多相关文章
- JS中encodeURIComponent函数用php解码的代码
JS中encodeURIComponent函数给中文编码后,如何用php解码?? 前提:编码前的中文可能是gbk,gb2312,utf-8等. 复制代码 代码如下: urldecode() iconv ...
- 关于 web中 使用 java.net.URLEncoder.encode 要编码两次呢 , js的encodeURIComponent 同理
因为在jsp中对中文进行了编码的时候用的是UTF-8的编码方式,而在servlet中调用request.getParameter();方法的时候使用服务器指定的原始编码格式(ISO-8859-1)自动 ...
- application x-www-form-urlencoded与JS的encodeURIComponent()
application/x-www-form-urlencoded 表单的enctype属性表示在发送到服务器之前应该如何对表单数据进行编码,默认值是application/x-www-form-ur ...
- js的encodeURIComponent与java的URLEncoder的区别
js中的encodeURIComponent这个函数和java中的URLEncoder有少数不一样的.如下表格就是区别 ascii java js + %20 ! %21 ! ' %27 ' ( ...
- 兼容火狐,ie8的 js urlencode和urldecode
function UrlEncode(str)//url编码{ var i,temp,p,q; var result=""; for(i=0;i<str.length;i++ ...
- js urlencode
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JS encodeURIComponent函数
为了避免歧义,可以用JS 的encodeURIComponent函数 将有歧义的字符(?+=等)转换成对应的ASCII编码 for(var i=0;i<whichform.elements.l ...
- Atitit.软件开发概念(11)--网络子系统--url编码 空格问题URLEncoder java js php
Atitit.软件开发概念(11)--网络子系统--url编码 空格问题URLEncoder java js php 1. RFC2396标准 including HTML 4.01 section ...
- PHP、JS 中 encode/decode
PHP : urlencode() urldecode() JS : encodeURIComponent() decodeURIComponent() 同一字符串,编码后的结果一样 1
随机推荐
- 在ASP.NET2.0里打印网页指定的内容(比如打印网页里的一个Table)
原文:在ASP.NET2.0里打印网页指定的内容(比如打印网页里的一个Table) 打印指定内容: <html> <head> <script type= " ...
- react学习笔记1--基础知识
什么是react A JAVASCRIPT LIBRARY FOR BUILDING USER INTERFACES[React是一个用于构建用户界面的JavaScript库.] React之所以快, ...
- HDU1051 Wooden Sticks 【贪婪】
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- EF中的EntityState几个状态的说明
之前使用EF,我们都是通过调用SaveChanges方法把增加/修改/删除的数据提交到数据库,但是上下文是如何知道实体对象是增加.修改还是删除呢?答案是通过EntityState枚举来判断的,我们看一 ...
- jQuery中的 return false, e.preventDefault(), e.stopPropagation()的区别
e.stopPropagation()阻止事件冒泡 <html><head> <title></title> <script sr ...
- csdn 博客,你很努力,有人帮你-2015年03一个月17日本
今天泛化 开始使用简书 正则表达式的博客写了两篇文章 回顾 Core Data 基本使用 总结 Xcode6新特性 简单聊聊 简书,事实上一開始学 MarkDown 语法的时候,已经用了,但是,一直认 ...
- SpringMVC1
itRed You are never too old to set another goal or to dream a new dream. SpringMVC一路总结(一) SpringMVC听 ...
- Net开源网络爬虫
转载.Net开源网络爬虫Abot介绍 .Net中也有很多很多开源的爬虫工具,abot就是其中之一.Abot是一个开源的.net爬虫,速度快,易于使用和扩展.项目的地址是https://code.goo ...
- GetDirectories 出错的解决方法
我想找到D盘里面所有 "*.pst文件,类似 windows 下的磁盘搜索功能, using System.IO; Directory.GetFiles(@"d:\", ...
- (c#2.0)serialPort串口通讯
原文:(c#2.0)serialPort串口通讯 using System; using System.Collections.Generic; using System.ComponentModel ...