3 // http://jquery.com/docs/ajax/
5 if ( typeof XMLHttpRequest == 'undefined' && typeof window.ActiveXObject == 'function') {
6 var 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
31 xml.open(type || "GET", url, true);
34 xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
37 // Set header so calling script knows that it's an XMLHttpRequest
38 xml.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
40 /* Force "Connection: close" for Mozilla browsers to work around
41 * a bug where XMLHttpReqeuest sends an incorrect Content-length
42 * header. See Mozilla Bugzilla #246651.
44 if ( xml.overrideMimeType )
45 xml.setRequestHeader('Connection', 'close');
47 xml.onreadystatechange = function() {
48 if ( xml.readyState == 4 ) {
56 // Hide loader if needed
57 if ($.xmlActive <= 0) {
68 $.httpData = function(r,type) {
69 return r.getResponseHeader("content-type").indexOf("xml") > 0 || type == "xml" ?
70 r.responseXML : r.responseText;
73 $.get = function( url, ret, type ) {
74 $.xml( "GET", url, null, function(r) {
75 if ( ret ) ret( $.httpData(r,type) );
79 $.getXML = function( url, ret ) {
80 $.get( url, ret, "xml" );
83 $.post = function( url, data, ret, type ) {
84 $.xml( "POST", url, $.param(data), function(r) {
85 if ( ret ) ret( $.httpData(r,type) );
89 $.postXML = function( url, data, ret ) {
90 $.post( url, data, ret, "xml" );
93 $.param = function(a) {
95 if (a && typeof a == 'object' && a.constructor == Array) {
96 for ( var i=0; i < a.length; i++ )
97 s[s.length] = a[i]['name'] + "=" + encodeURIComponent( a[i]['value'] );
100 s[s.length] = i + "=" + encodeURIComponent( a[i] );
105 $.fn.load = function(a,o,f) {
107 // I overwrote the event plugin's .load
108 // this won't happen again, I hope -John
109 if ( a && a.constructor == Function )
110 return this.bind("load", a);
113 if ( o && o.constructor == Function ) {
122 $.xml(t,a,o,function(h){
123 var h = h.responseText;
124 self.html(h).find("script").each(function(){
126 eval( this.text || this.textContent || this.innerHTML );
135 * function: $.fn.formValues
136 * usage: $('#frmLogin').formValues()
137 * docs: Gets the form values and creates a key=>value array of the found values (only for ENABLED elements!)
139 $.fn.formValues = function() {
141 this.find("input[@type='submit'],input[@type='hidden'],textarea,input[@checked],input[@type='password'],input[@type='text'],option[@selected]")
142 .filter(":enabled").each(function() {
144 o['name'] = this.name || this.id || this.parentNode.name || this.parentNode.id;
145 o['value'] = this.value;
153 * usage: $.update('someJQueryObject', 'someurl', 'array');
154 * docs: Mimics the ajaxUpdater from prototype. Posts the key=>value array to the url and
155 * puts the results from that call in the jQuery object specified.
156 * --> If you set the blnNoEval to true, the script tags are NOT evaluated.
158 $.update = function(objElement, strURL, arrValues, fncCallback) {
159 $.post(strURL, arrValues, function(strHTML) {
161 // Update the element with the new HTML
162 objElement.html(strHTML);
165 // Evaluate the scripts
166 objElement.html(strHTML).find("script").each(function(){
167 try { eval( this.text || this.textContent || this.innerHTML ); } catch(e){}
172 if (fncCallback) fncCallback();