在我的角度2 http.get是不正确的,然而,我不明白这是什么。
我试图从常规表单向ajax.php服务器文件发送3个输入字段数据,并通过echo命令从服务器发出警报。那样的话,我就能确定通信是有效的。虽然铬扩展程序与ajax.php服务器文件之间的通信是正确的(有正确的json响应),但我在应用程序中的角度代码只提醒响应对象。将对象解析为数据不起作用。有时反应是空白的。下面是我的角度代码:第一个文件- 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对象在浏览器中处于警报消息:{mail:danielgontar@gmail.com}。chrome扩展正确地显示了来自服务器的响应。
发布于 2017-05-07 05:31:47
你已经从你想要得到的URL中输入了四个“www.w”。
this.http.get('.delikates.co.il/ajax.php?name='+name+'&email='+email+'&mobile='+mobile)
试试看,我查过了,效果很好:
return this.http.get('http://www.delikates.co.il/ajax.php?name='+name+'&email='+email+'&mobile='+mobile)
.subscribe((data:Response)=>data.json()
);
https://stackoverflow.com/questions/43828100
复制相似问题