passing parameters to XMLHttpRequest’s onreadystatechange function
Tuesday, Nov 27. 2007 – Category: Code
I’ve been smashing my head against this all day – but I finally got something working consistently and reliable, so I better damn well document it. This is as good a place as any, and hopefully it will be useful to others.
I needed to make an Ajax call, so I turned to my good friend XMLHttpRequest. One wrinkle was that I needed to pass in a parameter to it… so I tried:
var test = "bar";
req = new XMLHttpRequest();
req.open("GET", myURL, true);
req.foo = test;
req.onreadystatechange = function() {
if (this.readyState != 4)
return;
if (this.status == 200) {
alert(this.foo); // should print out "bar"
}
}
req.send(null);
For the most part this worked. Except every now and then… when it didn’t. Most annoyingly, it failed pretty consistently when I was trying to use it within a nested Ajax call (complicated code, don’t ask.. it’s not interesting).
I’m not sure why it doesn’t work to be honest. From my understanding, req.foo should just instantiate a new foo member variable of the XMLHttpRequest object I just created and set it to be referenced via ‘this.foo’ inside any member function. I’m guessing it’s something to do with the scoping of onreadystatechange being set to the reference of an anonymous function so the anonymous function isn’t actually part of the XMLHttpRequest object and thus doesn’t have access to its member variables. What’s frustrating is that it works most of the time. A consistent failure model would actually be more helpful here.
Anyway, enough blabbering, here’s what seemed to work for me:
var test = "bar";
req = new XMLHttpRequest();
req.open("GET", myURL, true);
req.onreadystatechange = function(foo) {
return function() {
if (this.readyState != 4)
return;
if (this.status == 200) {
alert(foo);
};
}(test);
}
req.send(null);
Now that works reliably for me 100% of the time.
a dearth of packages
Friday, Nov 23. 2007 – Category: Grommit, OpenSolaris
This Thanksgiving I give thanks for all the packaging work underway in OpenSolaris. I look forward to a day in the future where I don’t have to spend so much time building out packages for all the updated software I need.
I’m building out the new Grommit machine, and part of what Grommit hosts is a whole bunch of Zones. I like to try to keep everything clean with pkg installs, so I’ve spent a good part of the past two days building Solaris (snv_75a) packages for Dovecot, PHP5, and Postfix.
Yes, I realise that packages for these already exist on Blastwave and elsewhere, but I want ones that leverage the Apache2, MySQL, and OpenSSL that Solaris already ships with. Anyway, thankfully the software all built fairly straight-forward which made my life a lot easier.
About the only thing left that I need is SpamAssassin and I’m hoping to use Eric B’s package that he put together for the OpenSolaris mail server for that. Eric passed me the Postfix package they use but unfortunately I ended up needing to rebuild it anyway since I wanted it to have TLS + SASL and authenticate against the Dovecot SASL.
I’ve done migrations of all the ZFS data for the home and web directories (yay for zfs send | ssh zfs receive), and I’ve installed Mailman (which I didn’t bother putting in a package since it cleanly separates itself in its own directory). I did a test migration of the MySQL database (which seemed to barf only on a field named ‘key’, which fortunately was easily worked around by escaping it with backticks). I’m pretty happy with the general build out of the machine so far. When I built out grommit last time it was early on in my days of using Solaris, so in general I’d made a mess of installing software all over the place, some in Blastwave, some from source, and things poorly and sloppily done everywhere. I’m trying to do things properly this time to make it easier to quickly commission zones that don’t require a whole bunch of finangling to get running cleanly.
I wonder if I can get grommit migrated by Sunday. That’d be a nice Thanksgiving surprise.
note to self: read notes to self
Thursday, Nov 22. 2007 – Category: Grommit
Urgh. Just spent 45 minutes trying to debug why my Postfix + Dovecot SASL setup wasn’t working. Reading the (very concise & well written) HOWTO on how to test it, it still wasn’t working. I knew how to do it, so I totally ignored reading my ~/Documents/Grommit/POSTFIXREADTHIS_IDIOT doc I wrote to myself last time I did this.
Finally, after 45 minutes – I gave up, and read my note to self I wrote 3 years ago. A very important line at the bottom said:
“If you have Perl special characters ($, &) in your password, don’t forget to escape them or the password base64 encoding won’t work. You just wasted an hour on this, dumbass.”
Sigh. I just updated it to “You just wasted an hour and 45 minutes on this, dumbass.”
sadly moving up in the ranks
Monday, Nov 19. 2007 – Category: Musings
oakland #4! oakland #4! oakland #4!
yeah, sad i know.
on the one hand i’m annoyed by the report, sure. but on the other hand, i’m annoyed by the people who are annoyed by the report.
In Oakland, Police Chief Wayne Tucker said people might be misled by the report. “The department is always interested in how we’re being rated,” he said, “but I think a rating can be very deceptive and ultimately give a false impression.” He said being ranked fourth on the list of dangerous cities could easily lead people to believe the whole city is under siege from crime.
I don’t think people reading the report will honestly believe the city is under siege, but let’s be honest – Oakland has an absurd amount of crime. Deceptive impressions go both ways. Tucker’s quote saying “crime is concentrated in “two reasonably small areas” in East and West Oakland.” is bullshit. There is crime all over Oakland, and while the Oakland PD has noticeably and admirably stepped up its efforts to combat it (and it has be on the decline, to be sure), I think having the press to put some more pressure and resources on the issue is a good thing.
new grommit online
Saturday, Nov 17. 2007 – Category: Grommit
yay, the new grommit machine is up and running…
[stevel@animalfarm:~] 507$ psrinfo -vp
The physical processor has 4 virtual processors (0-3)
x86 (GenuineIntel 6FB family 6 model 15 step 11 clock 2400 MHz)
Intel(r) Xeon(r) CPU X3220 @ 2.40GHz
[stevel@animalfarm:~] 508$ prtconf | grep "^Memory"
Memory size: 4095 Megabytes
[stevel@animalfarm:~] 509$ uname -a
SunOS animalfarm 5.11 snv_75 i86pc i386 i86pc
[stevel@animalfarm:~] 510$
ISRAEL ROCKS!!!!
Saturday, Nov 17. 2007 – Category: Football
every England fan owes Omer Golan a beer.
holy crap, can it get any more amazing than an Israel goal in stoppage time over Russia!?!?!?
…. too bad Owen is out now from the friendly with Austria.
Will McClaren finally given Jermaine Defoe the run he deserves now?
party time
Wednesday, Nov 14. 2007 – Category: Songbird

yeah! party time!
Songbird is co-hosting a party with Get Satisfaction tomorrow night. read the deets at our blog, and come on by!
nightingale is hatched
Tuesday, Nov 13. 2007 – Category: OpenSolaris, Songbird
Project Nightingale has officially been hatched, and I’m psyched to be able to post this with both the Songbird AND OpenSolaris blog tags. Albert (aka Triskelios) has done some impressive work already in trying to get XULRunner and Songbird ported over to OpenSolaris. We’ve hit some speedbumps though, and thought that formalising it into a project and getting some more eyes and hands on things would help speed it along. We’ve been approved and are being graciously sponsored by the Desktop Community.
I’m really psyched and looking forward to having the most kickass media player (no bias whatsoever) ported to and running on the best operating system (again, no bias whatsoever). Being able to combine my two favourite open source projects rocks.
So if you’re a desktop hacker, a media player expert, a Mozilla whiz, or just someone looking for a fun project to hack on – please join the project, and help out. We’ll have Albert’s patches posted soon, and we’ll be having our discussion in the Desktop forum, or you can subscribe to the Desktop mailing list.
Songbird going-on’s….
Thursday, Nov 8. 2007 – Category: Songbird
It’s been nice to see people talking more and more about adding supporting for Songbird or developing new sites and add-ons and translations to take advantage of Songbird’s APIs. The developer love is growing, can you feel it?
We also totally took out a huge amount of suck in the add-ons site so you can now filter, search, and sort on various variables making the site experience a whole lot better.
Anyone interested in digital media, and more specifically media on the web should drop by our office next Tuesday from 1-3pm. We’re starting to hold a series of talks (entitled “Media Web Meetups”) talking about the concept of the Media Web, and how open standards, protocols and formats will be utilised. Our first talk/discussion is going to be led by Mike Linksvayer, CTO of Creative Commons, and he’ll be talking about some of the recent upheaval in the media industry with Madonna, Trent Reznor, and Radiohead’s moves to publish music directly on the web. Should be a really interesting talk.
Closed processes and development in an open source world
Sunday, Nov 4. 2007 – Category: OpenSolaris, OpenSource, Songbird
I just read an interesting article on Linux.com criticising two examples of poor showing in the open source world, one revolving around a KDE icon theme, and the other around GIMP’s UI team.
Certainly I see some parallels in any open source project, both OpenSolaris & Songbird included.
First: my opinions. You didn’t ask for them, but you’ll get them anyway. Blogs rule like that. For the two examples cited in the article, I actually have differing opinions.
For the icon example, I disagree with the Oxygen project and agree with the writer. The icon developers gave up any rights they had to restrict redistribution with their license they published under. The derivative theme was well within its rights to redistribute the Oxygen icons.
For the GIMP UI example, I actually agree with the GIMP UI team. I think they way in which they phrased it could have been better. Perhaps instead of “I am afraid that I do not have positions open at the moment.”, he could have expanded and invited the volunteer to submit his work for review and inclusion without necessarily being a part of the formal GIMP UI team. While some people may disagree with me, I think UI work benefits from having a core team of people with a shared set of goals and design aesthetic. Adding another team member could alter that dynamic and/or add more overhead to the team.
Anyway – these are pertinent issues to both communities in which I participate in. OpenSolaris perhaps more than Songbird – since Songbird has no internal/closed repositories of source. But one prime example of a project people complain about is installation, or packaging – and I know I’ll probably get heat for this, but I think doing closed development is not that bad. The packaging project took some heat for doing its initial prototyping and development (I know I had at least one debate with sch about it
) between its team members before opening up and publishing its work. But given the conflict that can arise between people deriving work prematurely (e.g. the Oxygen case), or even just the issue of it being a design-in-progress (let alone a work-in-progress) means its often easier to be more agile and develop the core of the project between team members (whether that’s internal to Sun or involving external members).
Open source your work when you are ready – not when people ask you to
When you are ready for people to hack on your code, make derived works, and submit features and bugs – then you are ready for open source development. If you aren’t ready for those, then don’t. Open sourcing code isn’t free (assuming you care about your open source community – throwing code over the wall, as always, is cheap and easy – and you get what you pay for). If you want a thriving community then you have to be ready to spend time to cultivate it. If you’d rather be hacking on code to get something initially out – then you shouldn’t publish it initially.
Recent posts
- Gesture Lock
(Saturday, Nov 13. 2010 – 12 Comments) - ConnectIn 1.1.1 & HTC Sense UI
(Tuesday, Sep 28. 2010 – 38 Comments) - ConnectIn
(Saturday, Sep 25. 2010 – 62 Comments) - Proguard, Android, Ant, and 3rd party external JARs
(Wednesday, Sep 22. 2010 – 18 Comments)
Categories
- Android
- Cars
- ChinaBlog
- Code
- Computers
- Development
- Food
- Football
- Grommit
- Linkage
- Movies&TV
- Music
- Musings
- OpenSolaris
- OpenSource
- Outdoors
- Pets
- Photos
- Quotage
- Rdio
- Songbird
- Sun
- Travel
Grommit
Mozilla
OpenSolaris
- alan burlison
- bonnie corwin
- eric boutilier
- glynn foster
- jim grisanzio
- mark nelson
- mike kupfer
- planet opensolaris
- stephen hahn
Songbird
Archives
- November 2010
- September 2010
- August 2010
- June 2010
- May 2010
- February 2010
- January 2010
- December 2009
- October 2009
- September 2009
- August 2009
- June 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- April 2004
- March 2004
- February 2004
- January 2004
- December 2003
- November 2003
- October 2003
- September 2003
- August 2003
- July 2003
- June 2003
- May 2003
- April 2003
- March 2003
- February 2003
- January 2003
- December 2002
- November 2002
- October 2002
- September 2002
- August 2002
- July 2002
- June 2002
- May 2002
- April 2002
- March 2002
