在我的HTML中,我有一个按钮,它触发对API的请求,该API应该请求用户列表,最好使用Json。 // HTML
<div class="container">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<div class="form-area">
<form #userform="ngForm" (ngSubmit)="onClick(userform)" >
<br style="clear:both">
<h3 style="margin-bottom: 25px; text-align: center;">Login Form</h3>
<div class="form-group">
<input type="text" class="form-control" id="username" name="username" placeholder="Username" required [(ngModel)]="log.username" >
</div>
<div class="form-group">
<input type="Password" class="form-control" id="pwd" name="password" placeholder="Password" required [(ngModel)]="log.password">
</div>
<button type="submit" id="submit" name="submit" class="btn btn-primary pull-right" [disabled]="userform.invalid">Login</button>
</form>
</div>
</div>
<div class="col-md-4">
</div>
</div>
<div><button class="btn btn-primary" type="submit" (click)="test()">Test</button></div>
</div>
// ts file
这是ts文件,参见test()函数
test(){
this.authenticate.testing().subscribe(res=> {
this.data=res.json();
console.log(this.data);
})
}
格式是对还是
//服务档案
testing(){
let params = new URLSearchParams();
params.set('key', 'null');
params.set('username', 'sundhar@sample.net');
params.set('password', 'welcome');
params.set('format', 'json');
return this.jsonp.get('http://localhost:9000/EzeeShipping_Java/users' , {search: params }).map(response => response.json());
}
它显示错误,如
错误响应{_body:“注入JSONP的脚本没有调用回调。”,状态:200,ok:true,statusText:“Ok”,header:Headers,...}
我需要获取json并希望在屏幕上显示用户列表,请帮助我获取json文件