I'm coding a jquery plugin that act as a loading link that sends a request to a server using GET or POST now the thing is really basic but I cannot figure it out, maybe I'm tired, hehehehe.
Here is my code
Plugin instantiation:
$('#load-products-button').loadingLink({
params: function(){
return {
provider_id: $('#provider_id').val()
}
},
method: 'post',
success: function(res){
alert('ok');
}
});
And the code that makes the call is:
var params = settings.params ? settings.params : null;
$[settings.method](url, params)
.success(function() {
settings.success.apply(this, arguments);
})
.fail(function() {
settings.error.apply(this, arguments);
})
.complete(function() {
//remove the loading html
link.html(currentHtml);
});
The thing is that when sending the post request the params are not sent because them contain a function call, the post request is delivered with no parameters.
If I replace the params with an object like {provider_id: $('#provider_id').val()} it works correctly but sending params on plugin instantiation is not working to me.
How to eval the params before sending?
Thanks in advance.
settings.paramsis a function, call it as one.var params = settings.params ? settings.params() : null;