How to call a PHP function from angular 4? I have written the below code in my files and it returns nothing.
.component.ts
constructor(private _server:ServerConnectService) {..}
$('#fileUpload').on('click', (e)=>
{
this._server.uploadImage("Testing..").done((res)=>{
console.log("uploadImage Response "+res); // I need a result->"PHP -> uploadImage() calling " and data here
});
});
.service.ts
export class ServerConnectService {
uploadImageUrl:string = "http://localhost/toolapp/uploadImage.php";
constructor(private _http:HttpClient) {
}
uploadImage(d){
var myFunction = 'uploadImage';
var data = {"data":d};
return $.post(this.uploadImageUrl+"?action="+myFunction,data).then((res)=>{ return res; })
}
uploadImage.php
<?php
header("Access-Control-Allow-Origin: *");
function uploadImage($data){
$res= "PHP -> uploadImage() calling ".$data;
echo $res;
}
?>
how to achieve this?
Thanks, Guru