Chomper Stomping
jQuery/JavaScript/CSS 3/HTML 5, Java/PHP/Python/ActionScript, Git, Chrome/Firefox Extensions, Wordpress/Game/iPhone App Development and other random techie tidbits I've collected



programming concepts

December 21, 2007
 

Open Source AJAX HttpRequest Object Creation

More articles by »
Written by: Christopher McCulloh

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.
***************************************************************



About the Author

Christopher McCulloh
E-Commerce developer at Finish Line Co-Author of HTML, XHTML and CSS All-in-one Desk Reference for Dummies Graduated from IU with a Bachelors of Media Arts and Science and a Certificate in Applied Computer Science. Tech Editor for Building Facebook Applications for Dummies and Building Websites All-in-one for Dummies 2nd Edition. Creator and maintainer of the Status-bar Calculator Firefox Extension Three years professional experience in Java E-Commerce Development and four years professional experience with PHP for a combined total of seven years professional JavaScript/HTML/CSS experience



 
 

 
Screen Shot 2012-05-02 at 10.23.54 AM

Douglas Crockford – JavaScript the Good Parts

Really good lecture on JavaScript, especially if you are new to the language from another language like Java.
by Christopher McCulloh
0

 
 
cloudwars

Let the Cloud Wars Begin!!!

This is all going the same direction. They are all going to end up with unlimited storage for the same price point per year, so, the sooner one of them calls it and just offers that, the better that one will do. They need to ju...
by Christopher McCulloh
0

 
 
logo

dynode Batch Get Item

Working a lot with node.js, dynode and dynamoDB recently. Still trying to wrap my head around it all. Had a horrible time getting dynode.batchGetItem to work. Here is the error I was getting: { name: 'AmazonError', type: 'Valid...
by Christopher McCulloh
0

 

 
mysqlerror

WP phpBB Bridge: Warning: mysql_set_charset() expects parameter 2 to be resource, boolean given

Warning: mysql_set_charset() expects parameter 2 to be resource, boolean given in wp-content/plugins/wp-phpbb-bridge/inc/widgets/wpbb_topics_widget.php on line 149 This is an error caused by the fact that the WP phpBB Bridge pl...
by Christopher McCulloh
0

 
 
 

Events Calendar Pro Nav Formatting Messed up on Empty Calendar

The Events Calendar Pro (from http://tri.be/) has a few problems. If you are trying to figure out why a calendar with no events in that month has completely screwed up header navigation, just put this line of code inside of tab...
by Christopher McCulloh
5