首页 > Linux操作系统 > Linux操作系统 > jqgrid中文问题
改为
var gdata = {page: ts.p.page, rows: ts.p.rowNum, sidx: escape(ts.p.sortname), sord:ts.p.sortorder, _nd: (new Date().getTime())}
page,和rows为数字,不存在中文问题,sord为asc或者desc也没有问题,然后在你asp接收页面中使用
unescape(request.querystring("sidx"))即可。
asp的json文件如下:
<%
response.Charset="utf-8"
'---------------------------------------
' JSONClass类
' 将Select语句的执行结果转换成JSON
'------------------------------------------
Class JSONClass
' 定义类属性,默认为Private
Dim SqlString ' 用于设置Select
Dim JSON ' 返回的JSON对象的名称
Dim DBConnection ' 连接到数据库的Connection对象
' 可以外部调用的公共方法
Public Function GetJSON ()
dim Rs
dim returnStr
dim i
dim oneRecord
' 获取数据
Set Rs= Server.CreateObject("ADODB.Recordset")
Rs.open SqlString,DBConnection,1,1
if page<>"" then
epage=cint(page)
if epage<1 then epage=1
if epage>rs.pagecount then epage=rs.pagecount
else
epage=1
end if
rs.pagesize = rows
rs.absolutepage = epage
' 生成JSON字符串
if Rs.eof=false and Rs.Bof=false then
returnStr="{ total: "& rs.pagecount &", page: "& page &", records: "& rs.recordcount &", rows:["
for j=0 to rs.pagesize-1
if rs.bof or rs.eof then exit for
' -------
oneRecord = "{id:" & chr(34) &Rs.Fields(0).Value&chr(34)&",cell:["
for i=1 to Rs.Fields.Count -1
'oneRecord=oneRecord & chr(34) &Rs.Fields(i).Name&chr(34)&":"
oneRecord=oneRecord & chr(34) &Rs.Fields(i).Value&chr(34) &","
Next
'去除记录最后一个字段后的","
oneRecord=left(oneRecord,InStrRev(oneRecord,",")-1)
oneRecord=oneRecord & "]},"
'------------
returnStr=returnStr & oneRecord
Rs.MoveNext
next
' 去除所有记录数组后的","
returnStr=left(returnStr,InStrRev(returnStr,",")-1)
returnStr=returnStr & "]}"
end if
Rs.close
set Rs=Nothing
GetJSON=returnStr
End Function
'私用方法,在类中使用
Private Function check()
End Function
'
End Class
%>
<%
dim page,rows,sidx,sord
page = request.QueryString("page") 'page
rows = request.QueryString("rows") 'pagesize
sidx = unescape(request.QueryString("sidx")) 'order by ??
sord = request.QueryString("sord")
if page="" then page = 1 end if
if rows = "" then rows = 10 end if
if sidx = "" then sidx = "id" end if
if sord = "" then sord ="asc" end if
%>
'下面为使用示例
<!--#include file="conn.asp" -->
<%
server.ScriptTimeout=9000
dim a
set a=new JSONClass
a.Sqlstring="Select id,学号,姓名,学籍号 From t_学生信息 order by "& sidx & " " & sord
a.dbconnection=conn
response.Write(a.GetJSon())
conn.close()
set conn = nothing
'Set bjStream = Server.CreateObject("ADODB.Stream")
'With objStream
' .Type = 2
' .Mode = 3
' .Open
' .Charset = "utf-8"
' .Position = objStream.Size
' .WriteText= a.GetJSon()
' .SaveToFile Server.MapPath("a1.txt"),2
' .Close
'End With
'Set bjStream = NoThing
%>
html页面
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7383074/viewspace-586811/ ,如需转载,请注明出处,否则将追究法律责任。