如何调用从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;
}
?>
如何实现这一目标?
谢谢,大师
你必须调用HTTP GET或POST API,然后你可以使用PHP函数。
角是不呈现,因此下面的代码将不被PHP引擎被解析以生成所需的javascript服务器端。你将不得不暴露与POST界面,接受图像作为文件或base64
编码字符串一个REST API。
然后,采用了棱角分明HttpClientModule或HTTP模块可以将图像发送到相应的服务。