About | Blog | Publications | Projects | Resume | Contact

Follow Me

AddThis Feed Button
Subscribe to me on FriendFeed

 

Currently Reading

Tuesday, October 04, 2005

SAXF (Simple Asynchronous XMLHTTP Functions)

I'd like to share some really basic Javascript code that handles asynchronous XMLHTTP functionality in a bit more of a generic way than you can accomplish by hand coding each request. This is REALLY simple stuff, but I found it to be useful. It's not like the fullblown "AJAX frameworks", and it isn't intended to be. It's just a starting poing for doing basic work with the XMLHTTP object.

You can see the code here.

Here's the simple usage of the functions:

var xmlRequest = "SOME REQUEST TO POST";
saxf_sendAsync("http://tempuri.org/", xmlRequest, ReceiveSingleValue);

function ReceiveSingleValue(ResponseText, ResponseStatus)
{
 alert(ResponseText);
}

And here's a situation where you need to wait for two requests to return before doing anything:

var xmlRequest = "SOME REQUEST TO POST";
saxf_sendAsync("http://tempuri.org/page1", xmlRequest, ReceiveFirstValue);
saxf_sendAsync("http://tempuri.org/page2", xmlRequest, ReceiveSecondValue);

var FirstReturned = false;
function ReceiveFirstValue(ResponseText, ResponseStatus)
{
 if (SecondReturned)
  EverythingBack();

 FirstReturned = true;
}

var SecondReturned = false;
function ReceiveSecondValue(ResponseText, ResponseStatus)
{
 if (FirstReturned)
  EverythingBack();

 SecondReturned = true;
}

function EverythingBack()
{
 alert("We got both back");
}

posted by Chip Childers @ 6:33 PM   0 comments
Links to this post

Links to this post:

Create a Link

0 Comments:

Post a Comment

<< Home

 

© 2005, Jerry W Childers, Jr. - This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License.
Creative Commons License