Prototype 1.5.0 and json.js

written by jeremy on January 21st, 2007 @ 03:33 PM

I updated to Prototype 1.5.0 for a web app I’m developing, and all of a sudden Firefox starts choking on my code….
Exception ``[object Object]'' thrown from function anonymous(value=string:"get") in <http://ascend.local/javascript/prototype.1.5.0.js> line 407.
Exception ``[object Object]'' thrown from function anonymous(value=string:"get") in <http://ascend.local/javascript/prototype.1.5.0.js> line 328.
Exception ``[object Object]'' thrown from function anonymous() in <http://ascend.local/javascript/prototype.1.5.0.js> line 330.
Exception ``[object Object]'' thrown from function anonymous(iterator=function:anonymous) in <http://ascend.local/javascript/prototype.1.5.0.js> line 541.
Exception ``[object Object]'' thrown from function anonymous(iterator=function:anonymous) in <http://ascend.local/javascript/prototype.1.5.0.js> line 326.
Exception ``[Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.setRequestHeader]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://ascend.local/javascript/prototype.1.5.0.js :: anonymous :: line 916" data: no]'' thrown from function anonymous() in <http://ascend.local/javascript/prototype.1.5.0.js> line 916.
Exception ``[Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.setRequestHeader]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://ascend.local/javascript/prototype.1.5.0.js :: anonymous :: line 916" data: no]'' thrown from function anonymous(url=string:"http://ascend.local/remote_fakeout/process.php") in <http://ascend.local/javascript/prototype.1.5.0.js> line 862.
Well, I’m using the json.js library from Douglas Crockford to parse the json results from the servlet and it sets a toJSONString method on each object. This ticket from Ruby On Rails trac provided the information that had eluded me for going on 28 hours. This:
915:     for (var name in headers) 
916:      if (typeof headers[name] != 'function')
917:   },
Needs to become this:
915:     for (var name in headers) 
916:       if (typeof headers[name] != 'function') 
917:       this.transport.setRequestHeader(name, headers[name]);
918:   },
in prototype.js if you want to use the json.js library and not have Firefox throw exceptions like beads during Mardi Gras.

I hope to one day understand OOP enough to know how to solve these issues in under a day. Until then I’ll seek constant reprieve from the hourly compulsion to end my pain with a sweet gunpowder symphony due to my small brain, lack of raw talent, and inability to comprehend the obvious.

Yay.

Now I can get back to writing the web application I was supposed to be 30 hours into at this point. I suck.

Comments

  • rocco@bluora.com.au on 31 Jan 04:03

    You many want to update your code sections... you've got the code you need to add the wrong way around. Thanks for code... i was getting confused with it too.
  • Setti on 03 Feb 06:13

    Ffffoooohh!! THANKS very big!!!!
  • Arkilus on 11 Feb 02:53

    Thanks SO MUCH man!!! That was a great problem for me.
  • dizzy2 on 14 Jun 01:33

    Very, very, very big thanks!!!!!
  • cowo on 04 Aug 09:02

    Most useful: I had this exception with Prototype 1.6 too. However, have a look here: http://www.prototypejs.org/learn/json Because Crockford implementation extends common Object class it is unsuitable for usage with Prototype. Prototype 1.5.1 and later feature an alternative JSON system.

Post a comment

Options:

Size

Colors