如何从angularJS获取php数据?
我已经能够将表单数据从angularJS发送到php,但我不知道如何做相反的事情。我目前正试图将$base64变量引入我的angularJS中,但我对如何这样做感到非常困惑。官方angularJS中的文档对我也没有多大帮助 $http JS PHP如何从angularJS获取php数据?,php,angularjs,Php,Angularjs,我已经能够将表单数据从angularJS发送到php,但我不知道如何做相反的事情。我目前正试图将$base64变量引入我的angularJS中,但我对如何这样做感到非常困惑。官方angularJS中的文档对我也没有多大帮助 $http JS PHP 您可以在成功回调中添加一个参数,以从服务器获取响应(如果可用) var base64 = ''; $http({ method : "POST", url : "../opencv/MakeGray/MakeGray.php"
您可以在成功回调中添加一个参数,以从服务器获取响应(如果可用)
var base64 = '';
$http({
method : "POST",
url : "../opencv/MakeGray/MakeGray.php",
data : MakeGray_Form,
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
}).
success(function(response){
base64 = response; //response will contain whatever server echos to it's standard output
})
.error(function(){});
也许这对你有帮助:我不明白这有什么关系?我的问题与php后端有关。@TheVillageIdiot我真的需要你的帮助!
<?php
$imgname = $_POST["FileName"];
$inputDir = "../../uploads/" . $imgname;
$outputDir = "../../processed/" . $imgname;
$MakeGray = "./makegray " . $inputDir . " " . $outputDir;
$runExec = exec($MakeGray, $out);
$type = pathinfo($outputDir, PATHINFO_EXTENSION);
$data = file_get_contents($outputDir);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
echo "$base64";
?>
var base64 = '';
$http({
method : "POST",
url : "../opencv/MakeGray/MakeGray.php",
data : MakeGray_Form,
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
}).
success(function(response){
base64 = response; //response will contain whatever server echos to it's standard output
})
.error(function(){});