搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

Learn More

Why does my Web Handler work with Internet Explorer, but not with Firefox

more options

I am trying to develop a web page that uses the Simile Timeline (http://code.google.com/p/simile-widgets/wiki/Timeline) with data from SQL Server.

In initial testing of my timeline I tested it with Example.xml, a static XML file in the correct format to be event data. I wrote the following in the appropriate place within mytimeline's Javascript: -

   var WebHandler = "Example.xml"
   tl.loadXML(WebHandler, function (xml, url) { eventSourceFamily.loadXML(xml, url) });

This worked fine with both Firefox and Internet Explorer. I then changed the assignment to

   var WebHandler = "GDBTimeline.ashx?Type=Family&Userid=" + getControlValue("input", "hdnUser");

so that invoked a web handler that could look up the SQL database and return the XML that I wanted, and wrote this web handler.

This works perfectly with Internet Explorer, but with FireFox the timeline band is blank. Yet when I examine the http traffic with Fiddler2 (http://www.fiddler2.com/fiddler2/) I see that with either browser there is a response from URL

  /GDB_pages/GDBTimeline.ashx?Type=Family&Userid=robertb

that returns the XML that it is supposed to.

I have previously used web handlers with Firefox before, with no problems. The Fiddler results conclusively show that the web handler is invoked, and returns the appropriate XML, and this XML is identical to the XML from the static test with Example.xml.

Where do I start looking for answers? I don't even know if this is a Simile problem, a Firefox problem, or an ASP.NET problem.

Thank you, Robert.

I am trying to develop a web page that uses the Simile Timeline (http://code.google.com/p/simile-widgets/wiki/Timeline) with data from SQL Server. In initial testing of my timeline I tested it with Example.xml, a static XML file in the correct format to be event data. I wrote the following in the appropriate place within mytimeline's Javascript: - var WebHandler = "Example.xml" tl.loadXML(WebHandler, function (xml, url) { eventSourceFamily.loadXML(xml, url) }); This worked fine with both Firefox and Internet Explorer. I then changed the assignment to var WebHandler = "GDBTimeline.ashx?Type=Family&Userid=" + getControlValue("input", "hdnUser"); so that invoked a web handler that could look up the SQL database and return the XML that I wanted, and wrote this web handler. This works perfectly with Internet Explorer, but with FireFox the timeline band is blank. Yet when I examine the http traffic with Fiddler2 (http://www.fiddler2.com/fiddler2/) I see that with either browser there is a response from URL /GDB_pages/GDBTimeline.ashx?Type=Family&Userid=robertb that returns the XML that it is supposed to. I have previously used web handlers with Firefox before, with no problems. The Fiddler results conclusively show that the web handler is invoked, and returns the appropriate XML, and this XML is identical to the XML from the static test with Example.xml. Where do I start looking for answers? I don't even know if this is a Simile problem, a Firefox problem, or an ASP.NET problem. Thank you, Robert.

由 robert.barnes@xtra.co.nz 於 修改

所有回覆 (1)

more options

Problem solved. The issue: Content Type was not correct.

Visual Studio creates the web handler with dummy code like this: -

   Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
       context.Response.ContentType = "text/plain"
       context.Response.Write("Hello World")
   End Sub

I wrote a database query that set a string variable to the XML I wanted: -

   Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
       Dim Outstring as string
       '   my logic to fill Outstring with XML
       context.Response.ContentType = "text/plain"
       context.Response.Write(Outstring)
   End Sub

This works with Internet Explorer. However it's not strictly correct: to make it work with other browsers as well,

       context.Response.ContentType = "text/plain"

should be

       context.Response.ContentType = "text/xml"

It now works with IE, FF, and Chrome, and presumably all others.