Ionic - request api php

0

Personal I'm trying to make a request go post in an api php, it returns me undefined. My provider:

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
/*
  Generated class for the ProviderAccessApi provider.

  See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  for more info on providers and Angular 2 DI.
*/
@Injectable()
export class ProviderAccessApi {
  host = "http://localhost/bullGreenCollect/";
  data: any;

  constructor(public http: Http) {
    this.data = null;
  }

autentication() {
    /*if (this.data) {
      // already loaded data
      return Promise.resolve(this.data);
    }*/

    // don't have the data yet
    return new Promise(resolve => {
        var url = this.host + 'P.php';
        var params = {name:'Augusto'};
      this.http.post(url, params)
        .map(res => res.json())
        .subscribe(data => {
          // we've got back the raw data, now generate the core schedule data
          // and save the data for later reference
          this.data = data.results;
          console.log(this.data);
          resolve(this.data);
        });
    });
  }


}

My php:

<?php

if (isset($_SERVER['HTTP_ORIGIN'])) {
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Max-Age: 86400');    // cache for 1 day
    }

    // Access-Control headers are received during OPTIONS requests
    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
            header("Access-Control-Allow-Methods: GET, POST, OPTIONS");

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
            header("Access-Control-Allow-Headers:        {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

        exit(0);
    }


$postdata = file_get_contents("php://input");
$decoded = json_decode($postdata);

$array = array('sl' =>$decoded->name);
echo json_encode($array);

Does anyone know why it does not return the post q parameter I passed?

    
asked by anonymous 25.05.2017 / 22:49

1 answer

1

This provider log console puts date and not this.data, see if something different is returned.

    
25.05.2017 / 23:09