aurelia aurelia-http-客户端 jsonp

aurelia aurelia-http-client jsonp

我尝试查询一个与 aurelia-http-client 不同源的 api。

我的代码非常简单:

import {HttpClient} from 'aurelia-http-client';

export class App {

    constructor(){

    console.log("constructor called");

        let url = 'http://localhost:8081/all';

        let client = new HttpClient();

        client
            .jsonp(url)
            .then(data => {
                console.log("datas");
                console.log(data);
            });

    }

}

没有任何反应,我可以在网络中看到调用了 url,我的 api 引擎记录了一个条目,但我从未输入 [=30= 的 "then" ]...

怎么了?

更新:

给你一些catch的截图

code source browser result

与 JQuery 在同一台机器上没有问题。

看完这篇文章后post 我尝试添加作品 "callback" 现在可以了!!!

所以调用 jsonp(url, 'callback')

client.jsonp(url, 'callback')

谢谢...

这可能不是一个直接的答案,而只是一个建议,我宁愿使用 aurelia API,因为我发现它更加一致和稳定。

只需将它作为插件添加到您的主目录中即可:

.plugin('aurelia-api', config => {
      config.registerEndpoint('github', 'https://api.github.com/');
    }); 

并将其用作: 从 'aurelia-api':

导入 {Endpoint}
@autoinject
export class Users{
  constructor(private githubEndpoint){
  }

  activate() {
    return this.githubEndpoint.find('users')
      .then(users => this.users = users);
  }
}

来源:https://aurelia-api.spoonx.org/Quick%20start.html