Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass angularjs value to PHP variable

Tags:

php

angularjs

I am starting with angularjs with ngStorage. I can save and display data successfully.

I display value as before

{{myobj.session}}

I would like to pass whatever stored value into php variable. Shown below is my imaginary logic and I know thats not gonna work. My question is how to assign such value into PHP variable in a correct manner?

<?php 
    $name = {{myobj.session}}
?>
like image 906
tashi Avatar asked Jul 26 '15 13:07

tashi


2 Answers

You can use this angular variable: students.tiffen_type
PHP variable : $value

<?php
    $value = "{{ students.tiffen_type }}";
?>
like image 69
Venkatesh Parihar Avatar answered Oct 18 '22 11:10

Venkatesh Parihar


You can do a ajax request like this:

$http({
        url: "urltopost.php",
        method: "POST",
        data: {
            data: variable
        }
    }).success(function(response) {
    console.log(response);
});

And on the backend you can get the variable like this

<?php
$request = json_decode( file_get_contents('php://input') );
$variable = $request->data

From there you can do everything you want with that variable, still I'm not sure what are you trying to achieve.

like image 20
AlexARH Avatar answered Oct 18 '22 10:10

AlexARH