D
D
Danil2015-10-19 10:41:23
JavaScript
Danil, 2015-10-19 10:41:23

How to properly organize ajax in backbonejs?

How to organize it correctly? Now I'm making requests via jQuery ajax, after that I'm doing collection.reser(data) and listening to the onReset event on the view to update it. How to do this via fetch() (I don't know if this is correct)?
I need to achieve the following:
1. I make a request to the server (send the selection criteria)
2. I get a response
3. I update the View.

Can you give an example of such functionality?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-10-19
@k12th

Correctly just through fetch. The principle is this:

view.listenTo(collection, 'sync', view.render); // встроенное событие, см. http://backbonejs.org/#Events-catalog
collection.fetch({reset: true}); // http://backbonejs.org/#Collection-fetch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question