简体   繁体   中英

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?

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')
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM