3 // http://jquery.com/docs/ajax/
5 if ( typeof XMLHttpRequest == 'undefined' && typeof window.ActiveXObject == 'function') {
6 XMLHttpRequest = function() {
7 return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') >= 0) ?
8 "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
13 // Counter for holding the active query's
16 $.xml = function( type, url, data, ret ) {
17 var xml = new XMLHttpRequest();
21 // Increase the query counter
25 // Show loader if needed
32 xml.open(type || "GET", url, true);
35 xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
39 // Set header so calling script knows that it's an XMLHttpRequest
40 xml.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
42 /* Force "Connection: close" for Mozilla browsers to work around
43 * a bug where XMLHttpReqeuest sends an incorrect Content-length
44 * header. See Mozilla Bugzilla #246651.
46 if ( xml.overrideMimeType ) {
47 xml.setRequestHeader('Connection', 'close');
50 xml.onreadystatechange = function() {
51 if ( xml.readyState == 4 ) {
52 if ( ret ) { ret(xml); }
59 // Hide loader if needed
60 if ($.xmlActive <= 0) {
72 $.httpData = function(r,type) {
73 return r.getResponseHeader("content-type").indexOf("xml") > 0 || type == "xml" ?
74 r.responseXML : r.responseText;
77 $.get = function( url, ret, type ) {
78 $.xml( "GET", url, null, function(r) {
79 if ( ret ) { ret( $.httpData(r,type) ); }
83 $.getXML = function( url, ret ) {
84 $.get( url, ret, "xml" );
87 $.post = function( url, data, ret, type ) {
88 $.xml( "POST", url, $.param(data), function(r) {
89 if ( ret ) { ret( $.httpData(r,type) ); }
93 $.postXML = function( url, data, ret ) {
94 $.post( url, data, ret, "xml" );
97 $.param = function(a) {
99 if (a && typeof a == 'object' && a.constructor == Array) {
100 for ( var i=0; i < a.length; i++ ) {
101 s[s.length] = a[i].name + "=" + encodeURIComponent( a[i].value );
105 s[s.length] = j + "=" + encodeURIComponent( a[j] );
111 $.fn.load = function(a,o,f) {
113 // I overwrote the event plugin's .load
114 // this won't happen again, I hope -John
115 if ( a && a.constructor == Function ) {
116 return this.bind("load", a);
120 if ( o && o.constructor == Function ) {
129 $.xml(t,a,o,function(h){
131 self.html(h).find("script").each(function(){
133 eval( this.text || this.textContent || this.innerHTML );
142 * function: $.fn.formValues
143 * usage: $('#frmLogin').formValues()
144 * docs: Gets the form values and creates a key=>value array of the found values (only for ENABLED elements!)
146 $.fn.formValues = function() {
148 this.find("input[@type='submit'],input[@type='hidden'],textarea,input[@checked],input[@type='password'],input[@type='text'],option[@selected]").filter(":enabled").each(function() {
150 o.name = this.name || this.id || this.parentNode.name || this.parentNode.id;
151 o.value = this.value;
159 * usage: $.update('someJQueryObject', 'someurl', 'array');
160 * docs: Mimics the ajaxUpdater from prototype. Posts the key=>value array to the url and
161 * puts the results from that call in the jQuery object specified.
162 * --> If you set the blnNoEval to true, the script tags are NOT evaluated.
164 $.update = function(objElement, strURL, arrValues, fncCallback) {
165 $.post(strURL, arrValues, function(strHTML) {
167 // Update the element with the new HTML
168 objElement.html(strHTML);
171 // Evaluate the scripts
172 objElement.html(strHTML).find("script").each(function(){
173 try { eval( this.text || this.textContent || this.innerHTML ); } catch(e){}
178 if (fncCallback) { fncCallback(); }