When starts my plugin it runs a trigger for loading data from mvc c# controller just once but the page is refreshing infinite (loop). When I press submit button is running ok.
Here is the problem:
if (opcoes) {
$.extend(defaults, opcoes);
$('#formPaginacao').trigger('submit');
}
Rest of code (works when I press button submit):
return this.each(function () {
function postProcessing(data) {
dados = data;
p.totalRegistros = dados.length;
defaults.totalPaginas = Math.ceil(p.totalRegistros / defaults.registrosPorPagina);
defaults.registroAtual = 0;
renderiza();
}
$('#formPaginacao').submit(function (e) {
e.preventDefault();
dados = null;
getValues();
e.stopPropagation();
});
function getValues() {
var dadosPesquisaForm = $('#formPaginacao').serialize();
var dadosPesquisaJson = JSON.stringify(dadosPesquisaForm);
var dadosEnvio = JSON.parse(dadosPesquisaJson);
$.ajax({
type: 'POST',
url: defaults.controleCarregaDados,
data: dadosEnvio,
dataType: 'json',
cache: false,
success: function (data) { postProcessing(data); },
async: true,
error: function (erro) {
alert('erro ajax=' + erro)
}
});
};
{...}
you have too much built into this. change your submit button to just a button
then you just need
This shouldn't be in an each statement either. just put it in
form.serialize will pass all of the values from your form back to the controller. the input on your controller should be the same model that you have defined on your view