服务器 XMLHttp 导致 IE 8 中的页面永远执行?

发布于 2025-01-07 14:56:47 字数 1115 浏览 0 评论 0原文

我从名为 Error1.asp 的页面中获取了以下代码。但每当它运行时,发布数据的页面永远不会显示。需要显示的是“default1.aspx”,但它永远不会在 IE8 中呈现。在 Firefox 和 Chrome 中,它使用如下相同的代码进行渲染,没有任何问题。 我怎样才能让这个 ServerXMLHttp 在 IE 8 中工作?我的电脑上有 Win 7 64 位。

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伪心 2025-01-14 14:56:47

答案已经被接受,但是为了其他读者的利益,这里的代码应该是这样的:-

 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 

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 
忱杏 2025-01-14 14:56:47

我怀疑这是一个浏览器问题,我认为发生的情况是您在页面上显示内容,然后更改内容类型,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"

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文