如何从角4调用PHP函数

问题描述 投票:0回答:2

如何调用从4角一个PHP函数?我在我的文件写入下面的代码,它没有返回。

    .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;
    }

    ?>

如何实现这一目标?

谢谢,大师

angular
2个回答
1
投票

你必须调用HTTP GET或POST API,然后你可以使用PHP函数。


1
投票

角是不呈现,因此下面的代码将不被PHP引擎被解析以生成所需的javascript服务器端。你将不得不暴露与POST界面,接受图像作为文件或base64编码字符串一个REST API。

然后,采用了棱角分明HttpClientModule或HTTP模块可以将图像发送到相应的服务。

© www.soinside.com 2019 - 2024. All rights reserved.