First of all. Please bear with my questions.
What I am doing is just performing an ajax request which will return a response data of string.
Here's my php
<?php
header('Access-Control-Allow-Origin: *');
echo 'Peenoise Crazy';
?>
Http request
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
let options = new RequestOptions({ headers: headers });
return this.http.post('./app/parsers/peenoise.php', '', options)
.then(val => console.log(val))
This doesn't work. But if I change the url into this http://localhost:8912/app/parsers/peenoise.php
. It works.
Questions
- Why
./app/parsers/peenoise.php
doesn't work? - If I change the url to
http://localhost:8912/app/parsers/peenoise.php
. Why do I need to putheader('Access-Control-Allow-Origin: *')
? It is on the same folder of my app. - How to use http.post without passing an url of
http://localhost:8912/route/to/phpfolder.php
?
Any help would be appreciated. Please guide me to this. Thanks