I am using Angular2 CLI for my frontend framework and using PHP for my backend.
this.http.post('assets/modify.php', '')
.subscribe(result => {
console.log("success post php file");
}
);
I want to use post method to run modify.php. However, I got error: POST XXXXX/assets/modify.php 404 (Not Found)
I can use get method to read the PHP with the same URL, it is working fine. But how can I use Post to run the PHP.
modify.php:
<?php
//lode the file
$contents = file_get_contents('button.json');
//Decode the JSON data into a PHP array.
$contentsDecoded = json_decode($contents, true);
//Modify the counter variable.
$contentsDecoded['button1Status'] = "booked";
//Encode the array back into a JSON string.
$json = json_encode($contentsDecoded);
//Save the file.
file_put_contents('button.json', $json);
?>
The folder structure is:
app------ user--------------- user.component.ts(I am runing get or post method here)
assets----button.json modify.php
when I use get method :
Request URL:http://localhost:4200/assets/modify.php Request Method:GET Status Code:304 Not Modified Remote Address:127.0.0.1:4200 Referrer Policy:no-referrer-when-downgrade
when I use post method:
Request URL:http://localhost:4200/assets/modify.php Request Method:POST Status Code:404 Not Found Remote Address:127.0.0.1:4200 Referrer Policy:no-referrer-when-downgrade
**Just for a update from people's help.
I found this and it help me figure out what happened to my scenario:
executing php files in a angular2cli app
SO I am thinking at the development stage, I need to have a web server can run PHP code.Will have a try on the build-in PHP Server.**