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 // Dynamic Form Submission
94 // Based upon the mailing list post at:
95 // http://jquery.com/discuss/2006-March/000424/
97 $.fn.serialize = function(callback) {
98 return this.each(function(){
101 .find("input:checked,hidden,text,option[@selected],textarea")
102 .filter(":enabled").each(function() {
103 a[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
105 $.xml( this.method || "GET", this.action || "", $.param(a), callback );
109 $.param = function(a) {
111 if (a && typeof a == 'object' && a.constructor == Array) {
112 for ( var i=0; i < a.length; i++ )
113 s[s.length] = a[i]['name'] + "=" + encodeURIComponent( a[i]['value'] );
116 s[s.length] = i + "=" + encodeURIComponent( a[i] );
121 $.fn.load = function(a,o,f) {
123 // I overwrote the event plugin's .load
124 // this won't happen again, I hope -John
125 if ( a && a.constructor == Function )
126 return this.bind("load", a);
129 if ( o && o.constructor == Function ) {
138 $.xml(t,a,o,function(h){
139 var h = h.responseText;
140 self.html(h).find("script").each(function(){
142 eval( this.text || this.textContent || this.innerHTML );
151 * function: $.fn.formValues
152 * usage: $('#frmLogin').formValues()
153 * docs: Gets the form values and creates a key=>value array of the found values (only for ENABLED elements!)
155 $.fn.formValues = function() {
157 this.find("input[@type='submit'],input[@type='hidden'],textarea,input[@checked],input[@type='password'],input[@type='text'],option[@selected]")
158 .filter(":enabled").each(function() {
160 o['name'] = this.name || this.id || this.parentNode.name || this.parentNode.id;
161 o['value'] = this.value;
169 * usage: $.update('someJQueryObject', 'someurl', 'array');
170 * docs: Mimics the ajaxUpdater from prototype. Posts the key=>value array to the url and
171 * puts the results from that call in the jQuery object specified.
172 * --> If you set the blnNoEval to true, the script tags are NOT evaluated.
174 $.update = function(objElement, strURL, arrValues, fncCallback) {
175 $.post(strURL, arrValues, function(strHTML) {
177 // Update the element with the new HTML
178 objElement.html(strHTML);
181 // Evaluate the scripts
182 objElement.html(strHTML).find("script").each(function(){
183 try { eval( this.text || this.textContent || this.innerHTML ); } catch(e){}
188 if (fncCallback) fncCallback();