Reputation: 21406
I have the following code from a page called Error1.asp. But whenever it runs, the page to which data is posted never shows up. What needs to show up is 'default1.aspx' but it never renders in IE8. In Firefox and Chrome it does render without any issues using the same code as below. How can I make this ServerXMLHttp work in IE 8? I have Win 7 64-bit on my computer.
Set xmlhttp = server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST","http://localhost/ClassicASPErrorHandling/default1.aspx",false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send "errorDesc=" & Server.HTMLEncode(Server.GetLastError().Description() )& "&errorDetailedDesc=" & Server.HTMLEncode(Server.GetLastError().ASPDescription()) & "&errorURL=" & strURL & "&errorLineNumber=" & Server.HTMLEncode(ASPErr.Line()) & "&errorFile=" & Server.HTMLEncode( ASPErr.File()) & "&errorSource=" & Server.HTMLEncode(ASPErr.Source()) & "&logonUser=" & strLogonUser & "&errorCode=" & Server.HTMLEncode(Server.GetLastError().ASPCode() )
Response.Write xmlhttp.responseText
Response.ContentType = "text/xml"
Response.Write xmlhttp.responsexml.xml
Set xmlhttp = nothing
Upvotes: 1
Views: 735
Reputation: 189495
An answer has already been accepted however for the benefit of other readers here is what the code should look like:-
Dim xmlhttp: Set xmlhttp = server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", "http://localhost/ClassicASPErrorHandling/default1.aspx", false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Dim lastErr: lastErr = Server.GetLastError()
Dim entityBody: entityBody = "errorDesc=" & Server.URLEncode(lastErr.Description) _
& "&errorDetailedDesc=" & Server.URLEncode(lastErr.ASPDescription) _
& "&errorURL=" & Server.URLEncode(strURL) _
& "&errorLineNumber=" & lastErr.Line _
& "&errorFile=" & Server.URLEncode(lastErr.File) _
& "&errorSource=" & Server.URLEncode(lastErr.Source) _
& "&logonUser=" & strLogonUser _
& "&errorCode=" & lastErr.ASPCode
xmlhttp.send Replace(entityBody, "+", "%20")
Response.ContentType = "text/html"
Response.Write xmlhttp.responseText
Upvotes: 2
Reputation: 13243
I doubt this is a browser issue, i think what is happening is you are displaying content on the page, then changing the content type, IE may be having trouble understanding this, therefore, try this change in your code and see if it works out:
Set xmlhttp = server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST","http://localhost/ClassicASPErrorHandling/default1.aspx",false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send "errorDesc=" & Server.HTMLEncode(Server.GetLastError().Description() )& "&errorDetailedDesc=" & Server.HTMLEncode(Server.GetLastError().ASPDescription()) & "&errorURL=" & strURL & "&errorLineNumber=" & Server.HTMLEncode(ASPErr.Line()) & "&errorFile=" & Server.HTMLEncode( ASPErr.File()) & "&errorSource=" & Server.HTMLEncode(ASPErr.Source()) & "&logonUser=" & strLogonUser & "&errorCode=" & Server.HTMLEncode(Server.GetLastError().ASPCode() )
Response.ContentType = "text/xml" //THIS SHOULD HAPPEN BEFORE USING RESPONSE.WRITE
Response.Write xmlhttp.responseText //DO NOT DO THIS UNLESS DATA IS XML BECAUSE OF CONTENTTYPE
Response.Write xmlhttp.responsexml.xml
Set xmlhttp = nothing
And if you're trying to display NON-XML data on a ContentType = "text/xml"
page, i can assure you IE would probably be the first browser that would give issues. Make sure the only content written to the page is XML or change your ContentType = "text/html"
Upvotes: 1