我如何通过AJAX调用HTML - Elgg


How do I call HTML via AJAX - Elgg?

我试图通过AJAX在Elgg中调用视图,但在>>HERE<<

$('.glyphicon-zoom-in').click(function(event) {
    $( '.full-image-view' ).css( "color", "red" ).append('<div>Hope this works</div>');
    // >>HERE<<
    var Ajax = require('elgg/Ajax');
    var ajax = new Ajax();
    ajax.view('albums/inline_full_image_view', {
        data: {
                guid: 123 // querystring
            },
        }).done(function (output, statusText, jqXHR) {
            if (jqXHR.AjaxData.status == -1) {
                return;
            }
            $('.full-image-view').append(output);
        });
    });

输出: Hope this works

我哪里搞错了?

提前感谢大家。

inline_full_image_view.php

<?php
    echo 'Hello World';

egg使用需求。试试这个:

requirejs(["elgg/Ajax"], function(Ajax) {
    var ajax = new Ajax();
    //rest of your code!!
});
var xhr = new XMLHttpRequest();
xhr.open('GET', encodeURI('albums/inline_full_image_view'));
xhr.onload = function() {
    if (xhr.status === 200) {
        alert('User''s name is ' + xhr.responseText);
    }
    else {
        alert('Request failed.  Returned status of ' + xhr.status);
    }
};
xhr.send();