Home | Blog | Screencasts | Projects
# Sunday, November 23, 2008

I ran across an interesting bug with the JQuery thickbox, I pointed it to a URL which was an ASP.NET ashx handler that generates thumbnail images, the result in the browser was this garbled response:

 

image

 

Using Firebug we see that it expects the result to be text/html

image

Looking at the code it is obvious what the problem is:

 

   1: var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
   2: var urlType = baseURL.toLowerCase().match(urlString);
   3:  
   4: if (urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp') {//code to show images

 

The code looks at the extension of what it is calling, if it finds any of the common image types, it will send a different request type, so adding the .ashx extension will fix the issue:

 

   1: var urlString = /\.jpg$|\.jpeg$|\.png$|\.ashx$|\.gif$|\.bmp$/;
   2: var urlType = baseURL.toLowerCase().match(urlString);
   3:  
   4: if (urlType == '.jpg' || urlType == '.jpeg' || urlType == '.ashx' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp') {//code to show images

 

I’ve just simply added the .ashx as a file extension that should be treated as an image type, this fixed the issue.

Sunday, November 23, 2008 1:53:00 AM (E. Australia Standard Time, UTC+10:00)  #    Comments [0] - Trackback
code | JQuery
Statistics
Total Posts: 191
This Year: 4
This Month: 0
This Week: 0
Comments: 41