Side navigation
#1813 closed enhancement (wontfix)
Opened October 17, 2007 03:20PM UTC
Closed November 11, 2009 07:39PM UTC
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: |
Description
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; $.fn.extend({ 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); } }) } }); })(jQuery);
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?
Attachments (0)
Change History (2)
Changed December 11, 2007 05:05PM UTC by comment:1
component: | core → ajax |
---|
Changed November 11, 2009 07:39PM UTC by comment:2
milestone: | 1.2.2 → 1.4 |
---|---|
resolution: | → wontfix |
status: | new → closed |
version: | 1.2.1 → 1.3.2 |
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.