I am recieving data form controller in ajax. Then I should assign it to php variable but without using cookies. How to do it? My code:
$.ajax({
url: '/controller/action',
type: 'post',
data: {
id: id,
},
success: function(data){
if (data) {
//here I should assign data to php variable
}
if (!data) {
console.log('no data');
}
}
});
try using this demo code
<script>
if (data) {
var a =data;
<?php $abc = "<script>document.write(a)</script>"?>
}
if (!data) {
console.log('no data');
}
</script>
<?php
echo $abc;
?>
you can create a link with JavaScript that includes a GET variable. ones clicked php gets involved
code : http://example.org/index.php?q1=blablabla
Php code:
if(isset($_GET['q1']) {$ff = $_GET['q1']}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.