如何通过Elgg中的AJAX将数据从一个php文件传递到另一个?
data_from_here.php
<?php
$entity = elgg_extract('entity', $vars, FALSE);
$guid = $entity -> guid;
require_js('javascript_file.js');
javascript_file.js
require(['elgg/Ajax'], Ajax => {
var ajax = new Ajax();
$('.glyphicon-zoom-in').click(function(event) {
ajax.view('my_app/data_to_here', {
data: {
// I would like to pass $guid from data_from_here.php to guid here,
// so that js_guid will be == $guid from data_from_here.php
js_guid: $guid // Save the $guid from data_from_here.php in here
},
}).then(body => {
$( '.full-image-view' ).html(body);
})
});
});
data_to_here.php
// This is the file called by AJAX in javascript_file.js
// I would like to echo $guid from data_from_here.php here
// How do I get it from javascript_file.js
<?php
echo '<div class="full-image-view">$js_guid</div>';
答案 0 :(得分:0)
不要在PHP响应中使用HTML标记,只需使用JSON接收响应,然后根据需要为其添加标记。