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

Thox drupal-devel at drupal.org
Mon Jul 18 09:54:24 UTC 2005


Issue status update for 
http://drupal.org/node/23746
Post a follow up: 
http://drupal.org/project/comments/add/23746

 Project:      Drupal
 Version:      cvs
 Component:    base system
 Category:     feature requests
 Priority:     normal
 Assigned to:  Anonymous
 Reported by:  Thox
 Updated by:   Thox
 Status:       patch
 Attachment:   http://drupal.org/files/issues/drupal.js_3.patch (2.72 KB)

New patch, improved coding style of the whole drupal.js file.




Thox



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

1117209448 : 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.




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

1117286376 : Thox

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

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




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

1117287358 : 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.




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

1117289473 : Thox

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.




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

1117317736 : altano

Depending on how often you poll for data I can see it not being an
issue.


I had mine going with 50ms delays and left it overnight before I saw
the errors start to pop up.  Call me crazy =\




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

1121421984 : Thox

Attachment: http://drupal.org/files/issues/drupal.js_2.patch (1.31 KB)

My latest ajax-powered spellcheck module requires HTTPPost too. I'm keen
to see this function in core, as opposed to putting it in the module
itself.


I've updated it to allow sending of raw text to the recieving page,
where before it always encoded the text/object as form encoding.







More information about the drupal-devel mailing list