Reputation: 2066
So I have created a small javascript class that is supposed to AJAX post something in a PHP file. The class is the following:
var cms = cms || {};
cms.load_view = (function() {
return {
change: function() {
jQuery("#layout-switch a").on('click', function()
{
jQuery('#layout-switch a').removeClass('current');
jQuery(this).addClass('current');
var column_number = jQuery(this).attr('data-name');
var category = jQuery("#cat_id").val();
var data = {mode: column_number, cid: category};
this.postChange(data);
});
},
postChange: function(data) {
jQuery.ajax({
type: 'post',
url: SITEURL + "/modules/digishop/loadcategory.php",
data: data,
beforeSend: function () {
jQuery('#digishop').animate({
opacity: 0
}, 250, function () {
jQuery(this).addClass(column_number);
jQuery(this).animate({
opacity: 1
}, 250);
});
},
success: function (html) {
jQuery("#digishop").html(html);
}
});
return true;
}
}
})(jQuery);
jQuery(document).ready(function() {
cms.load_view.change();
});
However, when I click the selector Firebug says that postChange
is not a function when it is called in the first method, a.k.a. this.postChange(data);
Any ideas?
Thanks!
Upvotes: 2
Views: 3759
Reputation: 6655
Inside the change function, this
is a reference to the link you clicked. Replace this.postChange(data);
with cms.load_view.postChange(data);
.
Upvotes: 3