How can I go about passing data from one php file to another via AJAX in 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>';
This discussion is closed and is not accepting new comments.
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
Use data- attributes on your trigger. See elgg-lightbox logic for examples.
Just a note, you can use inline scripts, but they can only really call require().
So here's an example of passing $guid to a module:
Just a reminder, please don't post the same questions multiple times. I've closed this topic in favor of you other post: https://elgg.org/discussion/view/2516692/how-to-dynamically-pass-data-from-php-to-javascript-in-dynamically-created-html-elements