impregnable fiend impregnable fiend - 1 year ago 83
jQuery Question

Execute func in PHP depends on what's sent by Angular

met another challenge inspecting web development, will be grateful if anyone can help. So... I've got a few buttons each have to execute some func, like that

ng-click='loadA', ng-click='loadB'
etc. I'm making request like

$scope.loadA = function() {
method: 'POST',
url: 'generate.php',
data: {keyword : 'A'},
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
.then(function(data) {

On the backend I've got

$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$a = $request->keyword;
echo $a;

And even that simplified code return just empty object. Can't get what's wrong. Finally I want to receive on the serverside some 'keyword' and depends on that execute some func. In jQuery and PHP I've done it like

switch ($_POST['keyword']) {
case 'A':
case 'B':

But I'm stuck trying to perform it in Angular + PHP... So... Thanks in advance.

Answer Source

try this one.

$request = json_decode($postdata,true);
$a = $request["keyword"];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download