在JavaScript中设置phps $ _REQUEST ['variable_name'] [英] Set phps $_REQUEST['variable_name'] in JavaScript

查看:68
本文介绍了在JavaScript中设置phps $ _REQUEST ['variable_name']的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过javascript存储变量,以便我可以使用$ _REQUEST ['variable_name']在php中读取它。

is it possible to store a variable through javascript so that I can read it in php using $_REQUEST['variable_name'].

例如。
假设我有

for eg. let's say i have

$adcategory=$_REQUEST['category_id'];

在php页面的某个地方,我想在之前的某处预先设置变量 javascript,以便可以通过php读取。

somewhere in the php page, and I would like to pre set that "variable" somewhere before that in javascript, so that it could be read through php.

这有什么意义吗?这可能吗?

Does this make any sense? Is this possible?

感谢您的时间!
Andrej

Thank you for your time! Andrej

推荐答案

这不是一个技术问题,更多的是如何构建代码以及PHP后端之间的交互和页内Javascript。

It's less of a technical problem, more of how you structure your code and interaction between the PHP backend and in-page Javascript.

要将$ category_id变量转换为Javascript,典型方法是:

To get the $category_id variable into Javascript, the typical approach is:

<?php print "<script>category_id = $category_id;</script>";

要让您的Javascript代码将catid发送回PHP页面:

To have your Javascript code send a catid back to a PHP page:

$("#id").load("page.php?category_id="+category_id);

这会将它ping回PHP $ _REQEUST []数组。但问题是为什么你需要Javascript 中的可用变量

This would ping it back to PHPs $_REQEUST[] array. But the question is why you need the variable available in Javascript first.

这篇关于在JavaScript中设置phps $ _REQUEST ['variable_name']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆