如何通过AJAX传递数据 - Elgg
问题描述:
如何通过Elgg中的AJAX将数据从一个php文件传递到另一个文件?如何通过AJAX传递数据 - Elgg
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>';
答
不要在PHP响应使用HTML标记,只需使用JSON接收响应并根据需要附上标签。