So I am trying to pass a json object to my rest api which in turn will decode it and store it in my mysql database. The problem I am facing is that when I use the http.post function it does not pass my data or make the call to the site. I threw in a few console.logs so I know it is reaching the function but it is not getting past the post call.
I have tested it on my api side and it adds new data to the database when I pass in data through Chrome Poster so I do not believe the issue is there, plus I have echos in my api that will send messages confirming that a new entry was created or not.
I can oddly see those echos in my console when I use a http.get on my post url as well when I use an http.get on the post url it adds a new entry into my database. I am wondering if it may be an issue with my headers or if I am just using http.post incorrectly.
Here is where I make the http.post call. Data is an object made of data from user input.
newAlert(data) {
JSON.stringify(data);
console.log(data);
let myheaders = new HttpHeaders({
'Content-Type': 'application/json'
});
console.log("in new alert prior to post");
return new Promise(resolve => {
this.http.post(this.apiUrl+'/alerts/create.php', data, {headers: myheaders})
.map((response: Response) => {
console.log("in response");
console.log(data);
return response.json();
});
});
}