R
R
rie2014-07-26 18:36:38
JavaScript
rie, 2014-07-26 18:36:38

How to do the correct refactoring of ajax requests?

Hello.
About 2 months ago, I wrote a lot of code, according to the principle - "It worked."

var b = $("body");
b.on(event, element, function (e) {
  // .. код
  $.ajax({
    // .. код
  })
})

In short, there are really a lot of event handlers that send ajax requests to one file, and delegation from body is everywhere, the response is different everywhere, somewhere json, somewhere html, the parameters passed too. Size ~ 4k lines.
The first thing that comes to my mind now is the wrapper function.

How can all this be rewritten in a normal way? If possible, please tell me libraries or articles on this topic.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaly Zheltyakov, 2014-07-26
@rie

You need fullajax.
Send two parameters - a control command and arguments.
You return two parameters - a control command and data.

E
Evansive, 2014-07-26
@Evansive

Libraries for refactoring AJAX requests?
Push it into one function with the necessary arguments, and that's all.

M
Maxim Vasiliev, 2014-07-27
@qmax

MVC

G
Grag, 2014-07-27
@Grag

Compress the data you overeat, use fullajax and think about node.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question