使用DOM的XMLHttpRequest对象来发送xml请求,但当返回的响应带有中文时候,在PDA上无法正常显示,我使用MultiByteToWideChar也
使用DOM的XMLHttpRequest对象来发送xml请求,但当返回的响应带有中文时候,在PDA上无法正常显示,我使用MultiByteToWideChar也
[2 byte] By [
ciml-镜子] at [2007-12-16]
看看这能不能帮你忙?编码肯定是要转化的。另外问一下,你用什么通讯?我现在用cdpd通讯,但用xmlhttp发送后始终连不上服务器(status<>200,但截不到它的值),而用PDA上的IE打开服务器上的网页没问题,不知道问题出在哪里?
e-mail:426zh@sina.com
<%
Response.ContentType = "text/xml;charset=utf-8" 'it is required for the XMLHTTP.
Response.expires = 0
%>
<?xml version="1.0" ?>
<%
Dim objXMLDoc
Dim objXMLElement, objXMLRoot, objXMLTopic, objXMLNodes
Dim objConnection
Dim objRecordset
Dim objRecordsetField
Dim intRecordsEffected
public sub XMLErrorMessage
Set objXMLRoot = objXMLDoc.createElement("errormessage")
Set objXMLDoc.documentElement = objXMLRoot
Set objXMLNodes = objXMLDoc.createElement("state")
objXMLNodes.Text = objConnection.Errors(0).sqlstate
objXMLRoot.appendChild objXMLNodes
Set objXMLNodes = objXMLDoc.createElement("description")
objXMLNodes.Text = objConnection.Errors(0).Description
objXMLRoot.appendChild objXMLNodes
Set objXMLNodes = objXMLDoc.createElement("nativeerror")
objXMLNodes.Text = obJConnection.Errors(0).NativeError
objXMLRoot.appendChild objXMLNodes
Response.write objXMLDoc.xml
end sub
Function cn2un(strText)
For i = 1 To Len(strText)
c = Mid(strText,i,1)
cn2un = cn2un & "" & AscW(c) & ";"
'cn2un = cn2un & ChrW(AscW(c))
Next
End Function
Public Sub createResults()
Dim intRecords, intColumns
intColumns = 0
intRecords = 0
Set objXMLRoot = objXMLDoc.createElement("recordset")
objXMLDoc.documentElement = objXMLRoot
Set objXMLTopic = objXMLDoc.createElement("columns")
objXMLDoc.documentElement.appendChild objXMLTopic
For Each objRecordsetField In objRecordset.Fields
Set objXMLNodes = objXMLDoc.createElement("column")
objXMLNodes.setAttribute "id", Cstr( intColumns )
objXMLNodes.setAttribute "name", objRecordsetField.Name
objXMLTopic.appendChild objXMLNodes
intColumns = intColumns + 1
Next
While Not objRecordset.EOF
Set objXMLTopic = objXMLDoc.createElement("records")
objXMLTopic.setAttribute "id", CStr(intRecords)
objXMLRoot.appendChild objXMLTopic
For i = 0 To intColumns - 1
Set objXMLNodes = objXMLDoc.createElement("col")
if isNull ( objRecordset(i) ) then
objXMLNodes.Text = " "
else
objXMLNodes.Text = cn2un(trim( objRecordset(i) ))
end if
objXMLTopic.appendChild objXMLNodes
Next
intRecords = intRecords + 1
objRecordset.moveNext
Wend
objXMLRoot.setAttribute "effected", cstr( intRecords )
End Sub
Set objXMLDoc = Server.CreateObject( "MSXML2.DOMDocument" )
Set objConnection = Server.CreateObject( "ADODB.Connection" )
'objConnection.Open Request( "DSN" ), Request( "user" ), Request( "pass" )
objConnection.Open "localserver","sa","chapman"
on error resume next
'Set objRecordset = objConnection.Execute( Request( "sql" ), intRecordsEffected )
Set objRecordset = objConnection.Execute( "SELECT employeeID, LastName, FirstName,Title FROM Employees", intRecordsEffected )
'on error goto 0
if objConnection.Errors.Count = 0 then
call createResults
else
call XMLErrorMessage
end if
response.write replace(objXMLDoc.xml,"&","&")
set objConnection = nothing
set objXMLDoc = nothing
%>