IONIC2 Get POST data

0

I need to post a user id and collect the necessary information from the server (the server part already works) and return a JSON. Most of the problems I have had with the cors but despite having searched, I have not found the solution.

var link : String = "DIRECCION/PHP";

this.http.post(link.toString(), "HOLA=HOLA").subscribe(
  data => {
    console.log(data);
    return data;
  },
  error=> {
    console.error(error);
  },
  () =>
  {

  });
    
asked by Dalfageme 11.03.2017 в 00:04
source

1 answer

0

I think the problem may be in the parameters that you are sending, try to send a json. And if the request needs headers do not forget to send them too.

obj = {
   hola: 'hola'
}
var link : String = "DIRECCION/PHP";

 var headers = new Headers();
 headers.append('Accept', 'application/json');
 headers.append('Content-Type', 'text/plain');

this.http.post(link.toString(), this.obj, {headers: headers}).subscribe(
   data => {
     console.log(data);
     return data;
   },
   error=> {
    console.error(error);
   }
);
    
answered by 30.03.2017 в 09:43