如何将JavaScript函数数据导入到PHP变量中 [英] How to get JavaScript function data into a PHP variable
本文介绍了如何将JavaScript函数数据导入到PHP变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用PHP和JavaScript。我的JavaScript代码包含一个函数get_data():
function get_Data(){
var name;
var job;
.....
返回缓冲区;
$ / code>
现在我的PHP代码如下。
<?php
$ i = 0;
$ buffer_data;
/ *这里我需要从缓冲区的JavaScript get_data()获取值;
并分配给变量$ buffer_data。 * /
?>
如何将JavaScript函数数据分配到PHP变量中?
使用jQuery将JavaScript变量发送到您的PHP文件: $ url ='path / to / phpFile.php';
$ .get($ url,{name:get_name(),job:get_job()});
在您的PHP代码中,从 $ _ GET ['name' ]
和 $ _ GET ['job']
像这样:
<?php
$ buffer_data ['name'] = $ _GET ['name'];
$ buffer_data ['job'] = $ _GET ['job'];
?>
I am using PHP and JavaScript. My JavaScript code contains a function, get_data():
function get_Data(){
var name;
var job;
.....
return buffer;
}
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. */
?>
How do I assign the JavaScript function data into the PHP variable?
解决方案
Use jQuery to send a JavaScript variable to your PHP file:
$url = 'path/to/phpFile.php';
$.get($url, {name: get_name(), job: 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屋!
查看全文