【发布时间】:2017-05-07 05:19:59
【问题描述】:
我的 angular 2 http.get 中的某些内容不正确,但是,我不明白那是什么。
我尝试将 3 个输入字段数据从常规格式发送到 ajax.php 服务器文件,并通过 echo 命令提醒来自服务器的响应。这样我就可以确保通信正常。虽然 chrome 扩展程序与 ajax.php 服务器文件之间的通信正常(有正确的 json 响应),但我在应用程序中的 angular 代码仅会提示响应 [object object] 。将对象解析为数据不起作用。有时响应是空白的。这是我的角度代码: 第一个文件 - contact.component.ts ,方法 onSubmit() :
onSubmit(form:any)
{
this.name = form.value.name;
this.email = form.value.email;
this.mobile = form.value.mobile;
/* ajax call*/
alert(this.name+this.email+this.mobile);
alert(this.authService.send_lead_information(this.name,this.email,this.mobile));
}
second file - auth.service.ts :
import { Injectable } from '@angular/core';
import {Http, Response} from "@angular/http";
import any = jasmine.any;
@Injectable()
export class AuthService {
constructor(private http:Http) {}
send_lead_information(name,email,mobile)
{
return this.http.get('http://wwww.delikates.co.il/ajax.php?name='+name+'&email='+email+'&mobile='+mobile)
.subscribe((data:Response)=>data.json()
);
}
}
响应应该在浏览器的警报消息中作为 json 对象: {邮件:danielgontar@gmail.com}。 chrome 扩展程序正确显示来自服务器的响应。
【问题讨论】: