ASP生成JSON的问题
代码如下:
前台页面
$.getJSON(“AjaxService.asp?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格式,这样就不会有任何乱码问题了。
相关新闻>>
- 发表评论
-
- 最新评论 更多>>