Daniel Gontar
Daniel Gontar

Reputation: 157

No response from angular 2 http.get to php file

Something in my angular 2 http.get is not correct, However, I don't understand what that is.

I try to send 3 input fields data, from regular form, to ajax.php server file, and alert the response from the server via echo command. That way I will be sure that the communication is working. while communication is working between chrome extension program with the ajax.php server file correctly (there is proper json response), my angular code in the app alerts response [object object] ONLY . parsing the object to data does not work. Sometimes the response is blank . here is my angular code : first file - contact.component.ts , method 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()
                );
        }
    }

the response should be in alert message in the browser as a json object : {mail:[email protected]} . the chrome extension shows the response from the server correctly.

Upvotes: 1

Views: 461

Answers (1)

Kamlesh Jha
Kamlesh Jha

Reputation: 164

You have putted four no of "wwww" in the URL from where you are trying to GET.

this.http.get('http://wwww.delikates.co.il/ajax.php?name='+name+'&email='+email+'&mobile='+mobile)

Try This , It is working I checked:

 return this.http.get('http://www.delikates.co.il/ajax.php?name='+name+'&email='+email+'&mobile='+mobile)
        .subscribe((data:Response)=>data.json()
        );

Upvotes: 1

Related Questions