flpms
flpms

Reputation: 254

Two request at same route emberjs 2

This is my scenario.

  1. User input a zipcode and name location
  2. Load data from a API which a payload that contains a location list
  3. Show the location list for the user pick the right one.
  4. Then bind data to complete registration and submit registration

First I tried a modal as component. After I see this is incorrect, then I moved to ember-data and do this on the route. I create a ember-data for location list (which be a component) and other for register values. I create the adapter and a serializer. So I completely lost what do next. How I do this, using a ember-data to search places(a GET) and a registration(POST) on the API?

Upvotes: 0

Views: 177

Answers (1)

Bek
Bek

Reputation: 3207

if you have to make multiple requests at the same time you do

Ember.RSVP.all([
  $.ajax(...),
  this.store.findAll('person'),
  ...
]).then(function([result1, result2, result3 ]){
 console.log('all requests finished');
})

if you want sequential request (one after another) you simply chain them

$.ajax(...).then((ajaxResult) => { 
 return this.store.findAll('person')
}).then((person)=>{
 ....
}).then(function(){
 console.log('all requests finished')
})

Upvotes: 1

Related Questions