Bug Tracker

Opened 13 years ago

Closed 11 years ago

#1813 closed enhancement (wontfix)

Enhancement of the jQuery.fn.load ...?

Reported by: yereth Owned by:
Priority: minor Milestone: 1.4
Component: ajax Version: 1.3.2
Keywords: load, hybrid, jQuery.fn.load Cc:
Blocked by: Blocking:


I use this a lot myself; I needed a universal way to load any kind of link to any kind of item, so I changed the jQuery.fn.load in the following way:

(function($) {
$.fn._load = $.fn.load;

	load: function(url, args, callback) {
		// Backwards compatibility for the jquery load function
		if ($.isFunction(url)) return $(this)._load(url, args, callback);
		if (!this.length) return this;
		var url2 = url;
		if (args) url2 += (url2.match(/\?/) ? "&" : "?") + $.param(args);
		return this.each(function() {
			if (typeof this['location'] == 'object') this.location.href = url2;
			else if (typeof this['href'] != 'undefined') this.href = url2;
			else if (typeof this['src'] != 'undefined') this.src = url2;
			else {
				// Backwards compatibility for the jquery load function
				$(this)._load(url, args, callback);

Probably it's not perfect and can use refining. Perhaps I also missed a bit here, but it seems to work properly right now. Perhaps this can be added the the jQuery.fn.load native function?

Change History (2)

comment:1 Changed 13 years ago by john

Component: coreajax

comment:2 Changed 11 years ago by john

Resolution: wontfix
Status: newclosed

I like the idea behind this proposal although there are a few major concerns:

1) You modify .href. This will break any attempts to load HTML in an anchor element. 2) You ignore the callback. You should probably bind a load event to handle when the image or page has been loaded.

If you can resolve these two issues (and build a patch and write some test cases) I will definitely land this.

Note: See TracTickets for help on using tickets.