【问题标题】:No response from angular 2 http.get to php fileangular 2 http.get 对 php 文件没有响应
【发布时间】: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 扩展程序正确显示来自服务器的响应。

【问题讨论】:

    标签: angular http get response


    【解决方案1】:

    您在尝试 GET 的 URL 中输入了四个“wwww”。

    this.http.get('http://wwww.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()
            );
    

    【讨论】:

    • 尊敬的 Kamlesh Jha,感谢您的回答。我看到我的代码中有 3 w 。对不起,我不明白
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-12
    • 1970-01-01
    • 2017-05-10
    • 2017-05-13
    • 2016-11-23
    • 2017-11-20
    • 1970-01-01
    相关资源
    最近更新 更多