Friday, January 23, 2009

A simple basic and easy AJAX call for Javascript

Anyone looking to extend the use of their website or webpage will find that using AJAX calls will add a added dimension to the site. The use of AJAX allows you to call any external page and get the requested information and post it to your page without refreshing. It is rather simple. The following code can be transformed to do what you need but it gives the basic structure.

What you need is an event to fire.


<span onclick="AJAXCall('http://kcwaldo.blogspot.com/2008/10/simple-sql-select-statement.html','&Action=test','myspan')"> Click me</span>

<div id='myspan'>
Return information goes here.
</div>

Below is the script needed to run the event.


<script>

var hURL = '';
var hParamValues = '';
var hAc = '';
var hParamValuesa = '';

function handleHttpResponse()
{
if (http.readyState == 4)
{
if (http.responseText.indexOf('invalid') == -1)
{
document.getElementById(ActiveContainer).innerHTML = http.responseText;
isWorking = false;
//This is the queue.
if (hURL != '' && hParamValues != hParamValuesa){
AJAXCall(hURL,hParamValues,hAc);
hParamValuesa = hParamValues;
}
}
}
}
//url = url you are to get the data from
//paramvalues = are posted to the url. If you need querystring values then include //them in the URL.
//ac = the active container that the data returned will be pasted into. probably a //div or td or span

function AJAXCall(url,paramvalues,ac)
{

try
{
if (!isWorking && http)
{
if (ac == ''){return false;}
ActiveContainer = ac
document.getElementById(ActiveContainer).innerHTML = '';
http.open("Post", url, true);
http.onreadystatechange = handleHttpResponse;
isWorking = true;
http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
http.send(paramvalues);
}
else{
hParamValues = paramvalues;
hURL = url;
hAc = ac;
return false;
}
return true;
}
catch (e)
{
return false;
}
}

//This function creates a HTTP Object. It works in any browser, so far at least.
function getHTTPObject()
{
var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ // Internet Explorer
//alert(e.description);
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
//alert(e.description);
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
//alert(e.description);
//alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}

var ActiveContainer = '';
var isWorking = false;
var http = getHTTPObject();

</script>

Something the function above will do is to Queue up a second call so that. This is so if you have a list of links that you are showing a picture for it will make the first and last call but very few in between. Without the queue you can get very clunky behavior.

Please leave me a comment if you find this useful or something wrong.

Saturday, January 3, 2009

ScrapbookShelves



Posted by Picasa

ScrapbookShelves




Posted by Picasa

Simple Homemade Scrapbook Paper Shelves for $50 Part 2

Putting it all together.

I predrilled the holes with counter sinks at both ends of the 41" board and also at 14" from both ends. Depending on how accurate you are the idea is to create the space for the 13" shelves. You should have a 12" space in the middle. I did not fill in the space in the middle I left it open for us to add ribbon spools and other scrapbooking things.

Match up the holes and predrill them on the 60" board. Next step is to screw the 48" boards with the grooves lined up and facing each other to the 41" board and then the 60" board.

Make sure all is tight and then paint it or paper it or do your scrapbooking thing to it. Move it to the room and using a 2" x 1" x 3' board secure it to teh wall. Basically screw the support board to the shelf then stand the shelf up agains the wall and make sure everything is plum then screw the support board into the studs. We were initially going to hang this thing on the wall but we turned it upside down and set it on the floor and secured it to the wall.




My wife has yet to decorate it but my part is done.

Simple Homemade Scrapbook Paper Shelves for $50

Well my wife wanted some scrapbooking shelves or holders for christmas this year and once we started looking we found that they cost anywhere from $25 for 5 shelves to thousands for a cabinet that was nice and all but, too damn much IMO. So I decided to build a simple shelving unit that had a nice shelf on the end and would create a good amount of storage under the unit.

The original idea was 3 columns with 24 shelves each. She had a lot of paper and thought 72 shelves would be nice. It was going to hang on the wall. Then I was going to box in a few shelves below for holding other supplies. All in all it was going to be 60" across by 48" high with 3 colums of 13" X 13" shelves. It was going to use spoon shelf holders for the paper shelves to sit on. That was the original idea.

So I went shopping and found the wood I needed, and the screws, but when I came across the spoon holders I was a little surprised to see they wanted $5 for a set of 48. It was going to cost about $30 for just the holders, about as much as the wood. So I returned home and found out the neighbor had a unit built by someone and they just routered the shelf grooves. Which was free! Bingo!

So I returned and purchased the wood.
2 - 12" X 8' X 1" pine boards $9 each
1 - 12" X 10' X 1" pine board $12 each
3 - 4' X 8' X .25" hardboard sheets $5 each (Thinnest I could find and they are plenty strong enough)
1 Box of wood screws 2.5" $4 (You only need about 20 screws so this may not be needed)

I cut the 8' boards in half and routered slots approx 3/8" deep every 2" using a 1/4" bit. This was tricky doing the routering without any guides to keep the cuts straght. I'll be honest my lines were a little cricked :) I still don't know if I would rather pay for and use the spoon holders. In the end even my most crooked line was not even visible once the shelves were in place. Anyway if you have a drill but no router then I would just drill the holes ands use the spoons or wood dowls. Your choice.

I cut the 10' board into a 60" piece and a 41" piece. Then I lightly sanded by hand all the cut boards and edges.

I then using a table saw but you can also easily use a circular saw, cut the hardboard into 13.35" x 12.5" almost squares. They are set to be 13" wide plus the room for the grooves to hold them. They are set for 12.5" deep. a 12" wide board is actually 11.5" deep so in order to nat have board sticking out so far I reduced them a little. I also have a .75" X 2" X 3' board behind the shelves to secure them to the wall which gave me a little room behind for the shelves to slide back a little farther.

Part 2 putting it all together -->

Friday, January 2, 2009

Initial Start Image


This is the setup prior to the beginning.