I want to make the query to an api xxxxxx / yyy, just load a view, the problem is that when the page loads I do not receive an answer.
This is my code.
example.ts
ionViewWillEnter() {
this.chats.push("Hola prueba del chat");
this.asistenteProvider.chat("Hola")
.subscribe(res=>{
console.log("Respuesta enviando mensajex2",res);
this.chats.push(res);
},error=>{
console.log("error",error);
});
}
My provider
Example.provider.ts
export class EjemploProvider {
url:string;
constructor(public http: Http) {
this.url="/chat";
console.log('Hello');
}
chat(mensaje:string){
console.log("Mensaje a enviar",mensaje);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers});
return this.http.post(
this.url,
{
data:mensaje
},
options
).map(response=>{
return response.json();
}
)
}
}
When the view loads while viewing the console, messages appear, but not the status if the request has been received or rejected.
When I send the first message I get an error and I do not receive a response
When I send more messages after 2 ° the answer I still get errors but the answer is given
Then when I sent messages, I no longer get errors and I receive the answer correctly.
I am using a proxy to make the query to the api, because it has not activated cors. What is the reason?