Hello
It is very common to see ajax call blocks on the internet that always repeat the same structure extensively, I would like to improve my calls using parameterization patterns and save code from my processes.
Current status:
$.ajax({
type: "GET",
url: url,
dataType: "html",
timeout: 30000,
data:
{
//parametros
},
success: function(data)
{
//caso sucesso...
},
error: function (jqXHR, textStatus, errorThrown)
{
//caso erro
},
});
I would like to propose a function that is centralizing, something like callAjax ("POST", url, array)
But that's where the doubts come: 1) Considering that parameters can be an array (key / value) how to pass them whereas they can be 'n'?
2) How to work with the return of the function executed (success, error, complete) in the process / script that called the function?
I searched for examples of this paradigm but found nothing, thank you for any indication