Wednesday, February 15, 2006
Using the HTTP Response object to avoid unnecessary character encoding/decoding when making AJAX calls
The problem of getting weird characters in the code that causes XML documents to fail to parse is common when moving the sata between different client or server machines. Using the Response Object directly without character conversion in the code eliminates the problem
This ASP page code sample demonstrates how to do it.
This ASP page code sample demonstrates how to do it.
Dim objXMLHTTP, URL, xmldoc
URL = Request("url")
Response.ContentType = "text/xml"
Response.CharSet = "UTF-8"
Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
Call objXMLHTTP.Open("GET", URL, False)
Call objXMLHTTP.Send()
If Err.Number = 0 Then
If objXMLHTTP.Status = 200 Then
Set xmldoc = Server.CreateObject("Msxml2.DOMDocument")
xmldoc.async = false
xmldoc.load(objXMLHTTP.ResponseBody)
Else
xmldoc = ErrorXML("Service Unavailable - Status: " & objXMLHTTP.Status & "
URL: " & URL)
End If
Else
xmldoc = ErrorXML(Err.Description)
End If
xmldoc.save(Response)
Function ErrorXml(str)
Dim xmldoc
Set xmldoc = Server.CreateObject("Msxml2.DOMDocument")
xmldoc.async = false
xmldoc.loadXML("" & str & " ")
ErrorXml = xmldoc
End Function
Post a Comment