I have the following code snippet which, basically, through a jQuery
( $.ajax()
) request, uses selectors to fetch elements from a page (with content) and places inside elements of the current page using selectors of this.
$.ajax({
url: '/system/json/study/radar/uf-panorama-brasil.php?estado=' + this.sigla,
success: function (data) {
//retorna a tabela de #id natureza
var natureza = $(data).filter("#natureza");
$("#uf-natureza").html(natureza);
//retorna a tabela de #id segmento
var macrossegmento = $(data).filter("#macro");
$("#uf-macro").html(macrossegmento);
//retorna tabela de #id federal
var federal = $(data).filter("#federal");
$("#uf-programa-federal").html(federal);
//retorna tabela de #id estadual
var estadual = $(data).filter("#estadual");
$("#uf-programa-estadual").html(estadual);
//retorna tabela de #id municipal
var municipal = $(data).filter("#municipal");
$("#uf-programa-municipal").html(municipal);
}
});
Everything works perfectly. My question is this: is there any more elegant way to write this snippet of code? Because in the part that returns the result the code snippets are repeating themselves.