I’m following this documentation and use it to download and apply data to the DOM. However, I don’t seem to be able to apply it as I’m getting:
this.html is not a function: this.html(ajax_load);
Code:
(function( $ ){
$.fn.tasks = function() {
// there's no need to do $(this) because
// "this" is already a jquery object
// $(this) would be the same as $($('#element'));
$.ajax({
url: "include/tasks_handler.php?action=gettasks&list=default",
beforeSend: function() {
this.html(ajax_load);
},
success: function(html){
this.html(html);
}
});
};
})( jQuery );
$("#taskList").tasks();
I’ve also tried $(this), which stops it from breaking, but it’s not injecting the content to the selector.
Ideas?
thiswithin the ajax options refers to the options object and not the context of the plugin. A workaround is:This quick example demonstrates what’s happening:
This example better demonstrates what’s happening:
Fiddle: http://jsfiddle.net/GTScL/