我怎样才能通过JavaScript将数据从一个php文件传递到另一个文件 [英] How can I go about passing data from one php file to another via JavaScript
问题描述
如何通过JavaScript将数据从一个php文件传递到另一个文件?
data_from_here.php
<?php
$ guid = 99;
require_js('javascript_file.js');
javascript_file.js
require(['elgg / Ajax'],Ajax => {
var ajax = new Ajax();
$('。glyphicon点击(函数(事件){
ajax.view('root / data_to_here',{
data:{
guid:99 // save $ guid from data_from_here.php in here
},
})。then(body => {
$('.full-image-view').html(body);
})
});
});
data_to_here.php
<?php
echo $ guid;
php始终在页面之前执行交付,
它可以让你在javascript中编写php代码。
包含javascript作为javascript_file.js.php
或写入javascript文件中的一段。
data_from_here.php
$ guid = 99;
require_once('javascript_file.js.php');
javascript_file.js.php
<$ p $ ($'$'$'$'$'$'$'$'$'$'$'$'$'$'$'$' (函数(事件){
ajax.view('root / data_to_here',{
data:{
<)。 / pre>
这里我们在php中写入值
$ b $ pre $ guid: <?php echo $ guid?> //将data_from_here.php中的$ guid保存在这里
},
})。then(body => {
$('。 full-image-view').html(body);
})
});
});
data_to_here.php
<?php
echo $ _GET ['guid'];
?>
How can I go about passing data from one php file to another via JavaScript
data_from_here.php
<?php
$guid = 99;
require_js('javascript_file.js');
javascript_file.js
require(['elgg/Ajax'], Ajax => {
var ajax = new Ajax();
$('.glyphicon-zoom-in').click(function(event) {
ajax.view('root/data_to_here', {
data: {
guid: 99 // Save the $guid from data_from_here.php in here
},
}).then(body => {
$( '.full-image-view' ).html(body);
})
});
});
data_to_here.php
<?php
echo $guid;
The fact that php is always execute before the page is delivered, it permets you to write php code in the javascript.
for that include the javascript as a javascript_file.js.php or write the javascript in a section of the php file.
data_from_here.php
$guid = 99;
require_once('javascript_file.js.php');
javascript_file.js.php
require(['elgg/Ajax'], Ajax => {
var ajax = new Ajax();
$('.glyphicon-zoom-in').click(function(event) {
ajax.view('root/data_to_here', {
data: {
Here we write the value in php
guid: <?php echo $guid?> // Save the $guid from data_from_here.php in here
},
}).then(body => {
$( '.full-image-view' ).html(body);
})
});
});
data_to_here.php
<?php
echo $_GET['guid'];
?>
这篇关于我怎样才能通过JavaScript将数据从一个php文件传递到另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!