我可以在php中做这样的事情 angular js 值会分配到php值,任何技巧?
$phpVariable={{automation.start_flag}};
//echo $phpVariable;
<td> <?php echo $phpVariable ?></td>
想要将角度js值传递给php变量 有人可以帮我做吗?
块引用
答案 0 :(得分:3)
使用了ajax请求:
$http({
url: "YOUR_URL.php",
method: "POST",
data: {
data: variable
}
}).success(function(response) {
console.log(response);
});
对于后端,您可以获取变量:
<?php
$your_request = json_decode( file_get_contents('php://input') );
$your_variable = $your_request->data
?>
答案 1 :(得分:1)
$http({method: 'GET',url: '/someUrl'})
.success(function (response) {
$scope.resp = response
}, function(response) {
console.log(response)
});
HTML
<div>{{resp}}<div>
答案 2 :(得分:-1)
AngularJS
angular.module('scopeExample', []).controller('MyController', ['$scope', function($scope) {
$scope.username = '<?php echo $phpVariable; ?>'
$scope.sayHello = function() {
$scope.greeting = 'Hello ' + '<?php echo $phpVariable; ?>' + '!';
};
}]);
HTML
<td> {{username}}</td>
<td ng-init="sayHello"> {{greeting}}</td>