Use javascript variable in php code(在 php 代码中使用 javascript 变量)
问题描述
我一直在 joomla 中处理表单提交,但在使用 javascript 变量和 php JRoute_ 时遇到了一些麻烦
I have been working with a form submission in joomla and have a few trouble using javascript variable with php JRoute_
这是代码片段:
function ValidateForm()
{
var loc = $("#locality").val();
var action = '<?php echo JRoute::_('index.php?option=com_add&view=malllists&Itemid=233&districtname='.$dit.'&loc='Pass javascript Variable Here) ;?>';
document.miniSurveyView481.action = action;
}
代替 Pass javascript Variable 这里我需要传递 loc 值我尝试了很多东西但找不到解决方案.
In the place of Pass javascript Variable Here I need to pass the loc value I tried plenty of things but Could not find a solution.
推荐答案
您不能在 php 代码中使用 javascript 变量.Php 代码在服务器端运行,javascript 代码在客户端运行.你不能要求浏览器运行 php 代码.
You can't use javascript variable in php code. Php code run's on the serverside and javascript code runs in the client side. You can't ask the browser to run php code.
只有当代码到达浏览器时,您的变量 loc 才会有值.
Your variable loc will have a value only when the code reaches the browser.
如果您想从服务器获取一些值并将其与 javascript 变量结合,请执行以下操作.
If you want to get some value from server and combine it with javascript variables then do the following.
使用 ajax 请求并将所需的值发送到服务器.服务器将返回一个响应.使用该响应文本并将其存储在您的操作变量中.
Use an ajax request and send the desired values to server. The server will return with a response. Use that response text and store it in your action variable.
这篇关于在 php 代码中使用 javascript 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 php 代码中使用 javascript 变量
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
