我有2个跨域jsonp请求需要在另一个方法可以执行之前完成。所以,我想在$。当()函数如何使用jQuery.when()与多个jsonp请求?
$.when(getX(), getY()).then(createXY);
的getX()和的getY()使$。阿贾克斯()请求与独立JSONP回调的两个不同的领域。
与我原先的想法相反,createXY()在回调返回前被调用。 createXY()因此没有它需要的数据。
有人请给我提供一个例子,当多个异步jsonp请求完成时调用一个函数吗?
getX()和getY()返回什么?他们应该返回'$ .ajax()'返回的值。 – 2013-03-27 00:47:17
当涉及到承诺时避免jQuery [因为](http://abdulapopoola.com/2014/12/12/the-differences-between-jquery-deferreds-and-the-promisesa-spec/)和[因为]( http://stackoverflow.com/questions/23951745/is-any-jquery-version-compliant-to-promise-a-specifications)。 更好地使用像[lie](https://github.com/calvinmetcalf/lie)或[es6-promise](https://github.com/jakearchibald/es6-promise)这样的promise polyfill。 – jaydoubleyou 2015-05-21 07:45:15