【发布时间】:2018-09-04 11:05:54
【问题描述】:
我对 HTML 完全陌生,我想知道如何使用从服务器返回的 json 输出到 html 文件中。
更具体地说,我有一个 python 脚本,在执行时会给我一个 json 对象作为响应。我想通过浏览器将其打印在 html 文件中。我该怎么做?
我是否编写我的 html 以某种方式启动我的脚本并捕获对象?
【问题讨论】:
我对 HTML 完全陌生,我想知道如何使用从服务器返回的 json 输出到 html 文件中。
更具体地说,我有一个 python 脚本,在执行时会给我一个 json 对象作为响应。我想通过浏览器将其打印在 html 文件中。我该怎么做?
我是否编写我的 html 以某种方式启动我的脚本并捕获对象?
【问题讨论】:
例如,您可以浏览此代码,您可以在 sweetalert 中显示来自服务器的响应 组件:
subscription(subscriptionEmail: Object) {
this.contactusService.newsLetterData(subscriptionEmail).subscribe(res => {
console.log(res);
swal({
title: res['Message'],
type: 'success'
});
this.router.navigate(['home']);
});
}
服务:
newsLetterData( newsLetter: {}): Observable<boolean> {
return this.http.post<any>(AUTHURL + '/PageSlammer/newsLetter', { newsLetter})
.pipe(
map(result => {
// localStorage.setItem('loggdIn', 'true');
return result;
}),
);
}
【讨论】: