dongting3135 2016-07-07 18:11
浏览 35

如何通过AJAX传递数据 - Elgg

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>';
  • 写回答

1条回答 默认 最新

  • duanji1043 2016-07-07 18:24
    关注

    Don't use HTML tags in PHP response, just use JSON to receive response and upon that response, attach tags to it as per needed.

    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来