[英]aurelia aurelia-http-client jsonp
I try to query an api which is not the same origin with the aurelia-http-client. 我尝试查询与aurelia-http-client来源不同的api。
My code pretty simple : 我的代码很简单:
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);
});
}
}
Nothing happens, I can see in network that the url is called, my api engine logs an entry but I never enter in the "then" of the "promise"... 什么都没发生,我可以在网络中看到该URL被调用,我的api引擎记录了一个条目,但是我从未输入“ promise”的“ then” ...
What's wrong ? 怎么了 ?
Update : 更新:
I give you some screenshots with catch 我给你一些截图
code source browser result 代码源 浏览器结果
With JQuery on the same machine no problems. 与JQuery在同一台机器上没有问题。
After reading this post other jsonp case I try to add the work "callback" and now it works !!! 在阅读了这篇文章的其他jsonp案例之后,我尝试添加工作“回调”,现在它可以工作了!!!
so call jsonp(url, 'callback') 因此调用jsonp(url,'callback')
client.jsonp(url, 'callback')
Thanks... 谢谢...
This may not be a direct answer but just a suggestion, I would rather use the aurelia API as I found it more consistent and stable. 这可能不是直接的答案,而只是一个建议,我宁愿使用aurelia API,因为我发现它更加一致和稳定。
just add it as plugin in you main : 只需将其添加为main中的插件即可:
.plugin('aurelia-api', config => {
config.registerEndpoint('github', 'https://api.github.com/');
});
and use it as: import {Endpoint} from 'aurelia-api': 并将其用作:从'aurelia-api'导入{Endpoint}:
@autoinject
export class Users{
constructor(private githubEndpoint){
}
activate() {
return this.githubEndpoint.find('users')
.then(users => this.users = users);
}
}
Source: https://aurelia-api.spoonx.org/Quick%20start.html 资料来源: https : //aurelia-api.spoonx.org/Quick%20start.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.