如何将 JavaScript 函数数据放入 PHP 变量中 [英] How to get JavaScript function data into a PHP variable
本文介绍了如何将 JavaScript 函数数据放入 PHP 变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PHP 和 JavaScript.我的 JavaScript 代码包含一个函数 get_data():
I am using PHP and JavaScript. My JavaScript code contains a function, get_data():
function get_Data(){
var name;
var job;
.....
return buffer;
}
现在我的 PHP 代码如下.
Now I have PHP code with the following.
<?php
$i=0;
$buffer_data;
/* Here I need to get the value from JavaScript get_data() of buffer;
and assign to variable $buffer_data. */
?>
如何将 JavaScript 函数数据赋值给 PHP 变量?
How do I assign the JavaScript function data into the PHP variable?
推荐答案
使用 jQuery 将 JavaScript 变量发送到您的 PHP 文件:
Use jQuery to send a JavaScript variable to your PHP file:
$url = 'path/to/phpFile.php';
$.get($url, {name: get_name(), job: get_job()});
在您的 PHP 代码中,像这样从 $_GET['name']
和 $_GET['job']
获取变量:
In your PHP code, get your variables from $_GET['name']
and $_GET['job']
like this:
<?php
$buffer_data['name'] = $_GET['name'];
$buffer_data['job'] = $_GET['job'];
?>
这篇关于如何将 JavaScript 函数数据放入 PHP 变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文