HTTPDJS

HTTPDJS (HTTP Dynamic Javascript) is something I cooked up a while back when some of the available scripts out there had disappeared, or just were too buggy.

What does it do?

The problem with the XMLHttpRequest object, is that you cannot perform cross domain requests, something called the “same domain policy” comes into effect. This applies to other things such as iframes. I needed a way to perform requests from a remotely hosted forum (ProBoards in this case) that worked near enough like the XHR object. Before, I used to set a no content header in the PHP script, but there was no way to send data back without putting more work in, so I thought it was time for a script of my own.

So here it is, can’t remember when I created this. Might have been sometime last year. The zip file comes with an examples folder so you can see how it works (3 examples). The main things you need to do is include the HTTPDJS.js file, and the base64.js file (put above HTTPDJS.js). Next, you will need to edit the URL to the api.php file, this can be found in the HTTPDJS.js file.

GET and POST is supported.
Sending your own parameters is supported too.
Sending large amounts of data will be split up into parts and rebuild on the server.

Using it (example)

var request = new HTTPDJS();
var params = “action=post&user=peter&msg=hello";

request.isReady = function(){
   alert(request.responseText);
}

request.open("POST", “http://mydomain.com/post_message.php");
request.send(params);

The source

HTTPDJS.zip

Any questions, post below.

Tags:

Saturday, May 19th, 2007 JavaScript, PHP / MySQL, Programming

No comments yet.

Leave a comment

What Am I Doing?

Search

 

Categories