2012-02-20 17 views
1

我從一個叫Error1.asp頁面下面的代碼。但是無論何時運行,數據發佈的頁面都不會顯示。需要顯示的是'default1.aspx',但它永遠不會在IE8中呈現。在Firefox和Chrome中,它使用下面相同的代碼呈現沒有任何問題。 如何讓這個ServerXMLHttp在IE 8中工作?我的電腦上有Win 7 64位。服務器XMLHttp導致IE8中的頁面永久執行?

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 

回答

1

我懷疑這是一個瀏覽器的問題,我認爲正在發生的事情是,你在頁面上顯示的內容,然後改變,IE可能無法理解這種內容類型,因此,嘗試這種變化你的代碼,看看它是否工作了:

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 

如果你想一個ContentType = "text/xml"頁面上顯示非XML數據,我可以向你保證IE瀏覽器很可能是,這將使問題的第一個瀏覽器。確保寫入頁面的唯一內容是XML或更改ContentType = "text/html"

+0

我非常感謝你的出色答案。它解決了我的問題。我必須更改爲:Response.ContentType =「text/html」,並在所有寫入之前放置內容類型行。 CAN你明確如果我需要刪除行,其中你的評論「//不要這樣做,除非數據是XML ......」?我現在使用'text/html'。再次感謝。 – Sunil 2012-02-21 05:14:29

2

的答案已經然而,接受這裏其他讀者的好處是什麼代碼應該樣子: -

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