tech.agilitynerd.com

scratching that itch... 

Firefox Web Developer Add-on AJAX NON-Caching Problem

I ran across some "interesting" behavior of the Firefox Web Developer Add-on today. When editing JavaScript code I normally leave Web Developer set to "disable cache". This causes all images and, significantly for my purposes, the JavaScript files to be downloaded from the server on every page request. But I ran into a unexpected problem with this setting that cost me a couple hours today.

I was working on a legacy page today that uses an AJAX POST and the response is sent to an IFRAME. The POST was successful, the results were valid and present in the IFRAME. The problem was as soon as the content of the IFRAME was eval'd() a GET was being sent to the server for the URL of the page. This GET was a problem because it had a side effect of clearing the session data (which contained the POSTed AJAX data) for the current page. So when the page's FORM was finally POSTed the server couldn't find the data in the session.

After trying numerous code changes including disabling event handlers and events, it finally occurred to me that the cache disable feature of the add-on might be causing the unexpected GET. Sure enough, once I re-enabled caching the GET stopped being sent.

It was strange that the eval() caused the GET to be requested. All the other code around processing the IFRAME's data didn't trigger it, only the eval. Strange but true.

So just something to keep in mind when strange behavior occurs on AJAX pages where session data is being used.

Filed under  //   ajax   firefox   firefox addon   web development  

Comments [0]

Highlighter - Online Source Highlighting Service

I got tired of using <tt> elements to style the source code in this blog so I went looking for a tool that will convert code to html with syntax coloring. I found the online Highlighter service does a nice job.

It handles a number of languages including: C++, Java, JavaScript, Python, Ruby, XML, SQL and some others. The supplied CSS style sheet has reasonable defaults for coloring and allows you to modify the output to suite your needs. Here is an example of some Python code for my Googility site:

  1. class AtomLatestFeed(RssLatestFeed):  
  2.     feed_type = Atom1Feed  
  3.     subtitle = RssLatestFeed.description  
  4.     link = "/feeds/atom/"  
  5.   
  6.     def item_pubdate(self, item):  
  7.         return item.modified  

 

So give it a whirl. I'd be interested to know if there are other services anyone likes better.

Filed under  //   source highlighting   web development  

Comments [0]

reCAPTCHA in Django

I first read about ReCAPTCHA in this article in Wired magazine last year.


Copyright reCAPTCHA
reCAPTCHA provides a free CAPTCHA web service that pairs together two words from OCR scanned books. One of the words is known and the other couldn't be recognized. The user types in both words not knowing which is unknown to the system. As reCAPTCHA collects the responses for the unknown word they get human verified character recognition. So the millions of users of the system are clearing up millions of unrecognized words. It is a very clever human "cloud computing" system using only seconds of human effort for each use of the system.

I'm using a FIGLet based ASCII CAPTCHA on my websites since it was easy to integrate into the Blosxom writeback plugin. But I wanted to give reCAPTCHA a try while converting my Googility site to Django. John DeRosa made my job trivial by writing up the steps with a clear example.

So I followed his directions which involved installing the recaptcha-client python library on my dev and production systems and obtaining a free public/private license key from the reCAPTCHA site. Then I updated my Django view and template files for the one form that needed CAPTCHA protection. It was dead simple and working within minutes. The only minor addition I'd make to John's article is of course you need to pass the captcha_error variable from your view to the template: return render_to_response('edit.html', {'form': form, 'captcha_error':captcha_error}).

So give reCAPTCHA a try for your next project. It was so easy to do I might even convert my Blosxom blogs to use it via Lars Engel's recaptcha plugin.

Filed under  //   django   recaptcha  

Comments [0]