I am not a lawyer. I have very limited understanding of copyright law. Up until this point, in all of my AJAX programming that I did not use jQuery for, I have been using a code chunk found on page 18 of O’Reilly’s “Head Rush AJAX”.
I’m now writing a book about AJAX though, so I can’t just take that code chunk and put it in the book, right? I would assume that that code chunk is copyrighted by O’Reilly. Granted it’s only 20 lines of code, and uses no special functions or anything like that. It’s just a method of doing something. The problem is, that’s the only place I’ve seen this thing done that well, and that concisely.
I checked in two other textbooks, and both of them do it differently. Then I spent an hour or so scouring Google, and everywhere this code is done differently. So that backs up the “it’s copyrighted” theory even more. It’s not like they just went to ajax.com and copied a standard chunk of code from there. It’s their code that they wrote.
So I wrote my own code. It’s not as concise, but it behaves a little differently. I took the best of everything I saw everywhere and made my own.
But now if I use it for the book I’m writing, Wiley will own that chunk of code, since I wrote it for their book. Then if I write another book, let’s say for Random House, I will have to come up with a completely new method for creating the HttpRequest object across all browsers. I shudder at the thought.
So my solution is to post the method here, and place it under a modified version of the MIT license.
Here is the code:
function createHttpRequest(){
var httpRequest = null; //prepare the request object variable
if(window.ActiveXObject){
//try to make IE HttpRequest Object object
try{
httpRequest = new ActiveXObject(“microsoft.XMLHTTP”);
}catch (err){
try{
httpRequest = new ActiveXObject(“Msxm12.XMLHTTP”);
}catch (err){
alert (“error making request”);
}
}
}else if(window.XMLHttpRequest){
//try to make FF HttpRequest Object
try{
httpRequest = new XMLHttpRequest();
}catch (err){
alert (“error making request”);
}
}
return httpRequest;
}
Here is the license:
***************************************************************
Copyright (c) 2007 Christopher McCulloh
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
None. Do whatever you want with it. You don’t even have to include this license.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
***************************************************************










