当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 保证JavaScript和Asp、Php等后端程序间传值编码统一

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 保证JavaScript和Asp、Php等后端程序间传值编码统一


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 389 ::
收藏到网摘: n/a

在WEB开发过程中,前后端要求数据编码一致的处理是经常会碰到的! 在非英文字符集的页面上,如果使用Ajax方式进行数据交互的话,就必须要注意保证前后端数据的统一编码,否则,很容易就出现乱码!
在后端是ASP程序的情况下,保持前端Javascript和Asp之间传值的统一编码可以使用以下函数进行处理:
编码:escape(string)
解码:unescape(string)
这两个函数在JavaScript和Asp里都存在,而且功能完全一样,只要任何一端向另一端传数据,都先用escape进行编码,接收的一端用unescape进行解码即可保证Javascript和Asp数据传递过程中不会出现乱码!
在后端是PHP程序的情况下,保持前端Javascript和PHP之间传值的统一编码可以使用以下函数进行处理:
WEB前端JavaScript
编码:encodeURI(string)
解码:decodeURI(string)
WEB后端Php
编码:urlencode(string)
解码:urldecode(string)
同样,传值的时候使用相应的编码函数encodeURI或urlencode,接收的时候使用相应的解码函数decodeURI或urldecode,即可保证Javascript和Php数据传递过程中不会出现乱码!
在WEB前端Javascript解码,Php里urlencode编码的数据时,可能需要使用两次解码,如:
unescape(decodeURI(string))
unescape用来解一些非字符类的文字,如标点符号等等。