X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=ajax%2Fajax.js;h=87a90b348a570832503d4f50729c0b76c344f3e3;hb=6e69be66878c6fe384cbf42345337d19554ffbb6;hp=6339f7d74223f5cff61ce81cecb69e466d53e48f;hpb=d7856eb24b703d69aa616c0fb5972097e328712f;p=jquery.git diff --git a/ajax/ajax.js b/ajax/ajax.js index 6339f7d..87a90b3 100644 --- a/ajax/ajax.js +++ b/ajax/ajax.js @@ -115,7 +115,7 @@ $.fn.load = function(a,o,f) { f = o; o = null; } - if (o !== null) { + if (typeof o !== 'undefined') { o = $.param(o); t = "POST"; } @@ -124,7 +124,7 @@ $.fn.load = function(a,o,f) { h = h.responseText; self.html(h).find("script").each(function(){ try { - $.eval( this.text || this.textContent || this.innerHTML ); + $.eval( this.text || this.textContent || this.innerHTML || ""); } catch(e){} }); if(f){f(h);} @@ -141,37 +141,55 @@ $.fn.load = function(a,o,f) { */ $.fn.formValues = function(sButton) { var a = []; - var elp = {INPUT:true, TEXTAREA:true, OPTION:true}; + var ok = {INPUT:true, TEXTAREA:true, OPTION:true}; // Loop the shite $('*', this).each(function() { - // Skip elements not of the types in elp - if (!elp[this.tagName]) + // Skip elements not of the types in ok + if (!ok[this.tagName.toUpperCase()]) return; // Skip disabled elements if (this.disabled) return; - // Skip non-selected nodes - if ((this.parentNode.nodeName == 'SELECT') && (!this.selected)) + // Skip submit buttons and image elements + if ((this.type == 'submit') || (this.type == 'image')) + return; + + // Skip non-selected options + var oParent = this.parentNode; + var sNn = oParent.nodeName.toUpperCase(); + if (((sNn == 'SELECT') || (sNn == 'OPTGROUP')) && (!this.selected)) return; // Skip non-checked nodes if (((this.type == 'radio') || (this.type == 'checkbox')) && (!this.checked)) return; - // If we come here, everything is fine, so add the data - a.push({ - name: this.name || this.id || this.parentNode.name || this.parentNode.id, - value: this.value - }); + // If we come here, everything is fine + var sKey = this.name || this.id || oParent.name || oParent.id; + var sValue = this.value; + + // If we don't have an ID, and the parent is an OPTGROUP, + // get the NAME or ID of the OPTGROUP's parent + if ((!sKey) && (sNn == 'OPTGROUP') && (oParent = oParent.parentNode)) + sKey = oParent.name || oParent.id; + + // Add the data + a.push({ name: sKey, value: sValue }); }); // Add submit button if needed - if (sButton && (sButton !== null)) - a.push({ name: sButton, value: 'x' }); + if (sButton && (sButton !== null)) { + var el = $(sButton).get(0); + a.push({ + name: el.name || el.id || el.parentNode.name || el.parentNode.id, + value: el.value + }); + } + // Done return a; }; @@ -197,7 +215,7 @@ $.fn.update = function(sURL, sMethod, aValues, fCallback) { // Evaluate the scripts AFTER this (so you can allready modify the new HTML!) el.html(sResult).find("script").each(function(){ - try { $.eval( this.text || this.textContent || this.innerHTML ); } catch(e) { } + try { $.eval( this.text || this.textContent || this.innerHTML || "" ); } catch(e) { } }); // And call the callback handler :)