N
N
Nice_932017-07-05 11:25:18
WordPress
Nice_93, 2017-07-05 11:25:18

How to make a request to a url, wait for a response and send a request to another url?

there is a Promise
this.get('api').getUser(userId) after it is executed, take data from it make another request
this.get('api').getUserLogo(piece of url "api/user/logo/1" ) and then return everything, I have already re-read a bunch of everything but did not understand how it is done
Can you help

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaly, 2018-12-18
@ivanovav27

// SHARE BTN
//===============js======================
function socialopen(url){
    var winpar='width=500,height=400,left=' + ((window.innerWidth - 500)/2) + ',top=' + ((window.innerHeight - 400)/2) ;
    window.open(url,'tvkw',winpar);
}

$('a.bt').click(function(){
    var url = $(this).attr('href');
    socialopen(url);
    return false;
});

//===============html=====================
 <ul class="social_share">
        <li>
            <a class="bt" href="https://twitter.com/share?url=<?php the_permalink(); ?>&text=<?php the_title(); ?>">
                <i class="fa fa-twitter" aria-hidden="true"></i>
            </a>
        </li>
        <li>
            <a class="bt" href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>&title=<?php the_title(); ?>">
                <i class="fa fa-facebook" aria-hidden="true"></i>
            </a>
        </li>
        <li>
            <a class="bt" href="http://vkontakte.ru/share.php?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>">
                <i class="fa fa-vk" aria-hidden="true"></i>
            </a>
        </li>
    </ul>
The list with the .social_share class is inserted into each specific entry in the loop.

S
Stanislav Romanov, 2017-07-05
@Kaer_Morchen

return this.get('api').getUser(userId).then(user => {
  return Ember.RSVP.hash({
    user,
    logo: this.get('api').getUserLogo(кусок url "api/user/logo/1")
  });
});

A
Alexander Litvinenko, 2017-07-05
@edli007

Stanislav Romanov
Rather like this, according to the pattern

Promice.resolve().then( () => {
  return this.get( 'api').getUser( userId)
}).then( user => {
  return Ember.RSVP.hash({
    user,
    logo: this.get( 'api').getUserLogo( кусок url "api/user/logo/1")
  });
});

V
Vladimir, 2017-07-05
@Casufi

https://habrahabr.ru/company/mailru/blog/269465/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question