Changeset 2428
- Timestamp:
- 07/20/07 21:59:52 (1 year ago)
- Location:
- trunk/jquery/src
- Files:
-
- 2 modified
-
ajax/ajax.js (modified) (5 diffs)
-
jquery/jquery.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/src/ajax/ajax.js
r2420 r2428 76 76 ifModified: ifModified, 77 77 complete: function(res, status){ 78 // If successful, inject the HTML into all the matched elements 78 79 if ( status == "success" || !ifModified && status == "notmodified" ) 79 // Inject the HTML into all the matched elements 80 self.attr("innerHTML", res.responseText) 81 // Execute all the scripts inside of the newly-injected HTML 82 .evalScripts() 83 // Execute callback 84 .each( callback, [res.responseText, status, res] ); 85 else 86 callback.apply( self, [res.responseText, status, res] ); 80 self.html(res.responseText) 81 82 self.each( callback, [res.responseText, status, res] ); 87 83 } 88 84 }); … … 111 107 serialize: function() { 112 108 return jQuery.param( this ); 113 },114 115 /**116 * Evaluate all script tags inside this jQuery. If they have a src attribute,117 * the script is loaded, otherwise it's content is evaluated.118 *119 * @name evalScripts120 * @type jQuery121 * @private122 * @cat Ajax123 */124 evalScripts: function() {125 return this.find("script").each(function(){126 if ( this.src )127 jQuery.getScript( this.src );128 else129 jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" );130 }).end();131 109 } 132 110 … … 657 635 try { 658 636 status = isTimeout == "timeout" && "timeout" || 659 !jQuery.httpSuccess( xml ) && "error" || 660 s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" || 661 "success"; 637 !jQuery.httpSuccess( xml ) && "error" || 638 s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" || 639 "success"; 640 662 641 // Make sure that the request was successful or notmodified 663 642 if ( status != "error" && status != "timeout" ) { … … 784 763 // If the type is "script", eval it in global context 785 764 if ( type == "script" ) 786 jQuery.globalEval( data);765 (new Function( data ))(); 787 766 788 767 // Get the JavaScript object, if JSON is used. 789 768 if ( type == "json" ) 790 769 data = eval("(" + data + ")"); 791 792 // evaluate scripts within html793 if ( type == "html" )794 jQuery("<div>").html(data).evalScripts();795 770 796 771 return data; … … 824 799 // Return the resulting serialization 825 800 return s.join("&"); 826 },827 828 // evalulates a script in global context829 // not reliable for safari830 globalEval: function( data ) {831 data = jQuery.trim( data );832 if ( data ) {833 if ( window.execScript )834 window.execScript( data );835 else if ( jQuery.browser.safari )836 // safari doesn't provide a synchronous global eval837 window.setTimeout( data, 0 );838 else839 eval.call( window, data );840 }841 801 } 842 802 -
trunk/jquery/src/jquery/jquery.js
r2422 r2428 1172 1172 1173 1173 jQuery.each( a, function(){ 1174 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] ); 1174 if ( jQuery.nodeName(this, "script") ) { 1175 if ( this.src ) 1176 jQuery.ajax({ url: this.src, async: false, dataType: "script" }); 1177 else 1178 (new Function( this.text || this.textContent || this.innerHTML || "" ))(); 1179 } else 1180 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] ); 1175 1181 }); 1176 1177 1182 }); 1178 1183 }
