Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从angularJS获取php数据?_Php_Angularjs - Fatal编程技术网

如何从angularJS获取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"

我已经能够将表单数据从angularJS发送到php,但我不知道如何做相反的事情。我目前正试图将$base64变量引入我的angularJS中,但我对如何这样做感到非常困惑。官方angularJS中的文档对我也没有多大帮助

$http

JS

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(){});