ASP生成JSON的问题
代码如下:
前台页面
$.getjson(“ajaxservice.?uid=” + escape(option.value) + “&r=” + math.random(), function (date) {
if (date.success == 0) {
validatesettings.succeed.run(option);
namestate = true;
} else {
validatesettings.error.run(option, option.prompts.error.beused.replace(“{1}”, option.value));
namestate = false;
}
})
后台
<%@language=”vbscript” codepage=”65001′%>
<!–#include file=”json_2.0.4.asp”–>
<!–#include file=”conn.asp”–>
<%
response.charset=”utf-8′
dim data,uname
dim rs,sql
uname=request.querystring(“uid”)
uname=vbsunescape(uname)
set data = jsobject()
set rs=server.createobject(“adodb.recordset”)
sql=”selse * from table where field =’”&uname&”‘”
if rs.eof and rs.bof then
data(“success”)= -1
else
data(“success”) = 0
end if
data.flush
function vbsunescape(str)
dim x
x=instr(str,”%”)
do while x>0
vbsunescape=vbsunescape&mid(str,1,x-1)
if lcase(mid(str,x+1,1))=”u” then
vbsunescape=vbsunescape&chrw(clng(“&h”&mid(str,x+2,4)))
str=mid(str,x+6)
else
vbsunescape=vbsunescape&chr(clng(“&h”&mid(str,x+1,2)))
str=mid(str,x+3)
end if
x=instr(str,”%”)
loop
vbsunescape=vbsunescape&str
end function
%>
利用firefox调试时候,后台返回乱码,何解呀?
每个asp文件最顶端加上:
<%@language=”vbscript” codepage=”65001′%>
<%response.codepage=65001%>
<%response.charset=”utf-8′%>
asp文件保存成utf-8格式,这样就不会有任何乱码问题了。
上一篇: VB.NET多线程入门