[drupal-devel] [feature] Ajax HTTPPost javascript function

Thox drupal-devel at drupal.org
Sat May 28 14:11:15 UTC 2005


Issue status update for http://drupal.org/node/23746

 Project:      Drupal
 Version:      cvs
 Component:    base system
 Category:     feature requests
 Priority:     normal
 Assigned to:  Anonymous
 Reported by:  Thox
 Updated by:   Thox
 Status:       patch

I've got a working Drupal Ajax chat demo (using POST and GET requests)
here:
http://brandedthoughts.co.uk/chat


I've not (yet) had any unexpected errors thrown.




Thox



Previous comments:
------------------------------------------------------------------------

May 27, 2005 - 15:57 : Thox

Attachment: http://drupal.org/files/issues/drupal.js.patch (1.25 KB)

I needed to make HTTP posts of some information for an Ajax chat module
I'm testing, so I've added an HTTPPost() function to drupal.js.


It submits information like an HTML form would (using
x-www-form-urlencoded). I'm not sure if assuming all HTTPosts will be
encoded in this way is the best approach. I've never used any other
encoding, but that's just me.




------------------------------------------------------------------------

May 28, 2005 - 13:19 : Thox

Attachment: http://drupal.org/files/issues/drupal.js_0.patch (1.29 KB)

I've improved the coding style for a new patch.




------------------------------------------------------------------------

May 28, 2005 - 13:35 : altano

I'm developing an AJAX chat client for fun and I've come across a lot of
issues with XMLHttpRequest.


First off, every access of the object should be in a try catch block,
as exceptions can be thrown (especially with the send method) for no
decipherable reason.  You should handle these errors as well (a failed
send will require recreation of the XMLHttpRequest object... for some
reason trying to reuse them presents problems).  I just have a function
that creates the object and call it as needed.


Here is some code for initializing a more cross-browser XMLHttpRequest
object which can be thrown into a function:


	var xmlhttp;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE
versions.
	// and security blocked creation of the objects.
		try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		xmlhttp = false;
		}
		}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.overrideMimeType('text/xml');
	}


I honestly don't think AJAX is ready yet (for whatever), but I thought
I would try to be somewhat informative.







More information about the drupal-devel mailing list