[英]How to make AJAX calls - Elgg
我正在嘗試用elgg進行AJAX調用,但到目前為止我一直沒有成功。 我可能做錯了什么,或者我想念什么?
謝謝大家。
Elgg版本2.1.1
start.php
// in myplugin_init()
elgg_register_ajax_view('forms/myplugin/add');
默認/表格/ myplugin / add.php
<div>Successful AJAX call</div>
默認/對象/ my_ajax_plugin.php
<div class="myplugin-form-container">JQ Here</div>
<script type = "text/javascript" language = "javascript">
var Ajax = require('elgg/Ajax');
var ajax = new Ajax();
ajax.form('myplugin/add').done(function (output, statusText, jqXHR) {
if (jqXHR.AjaxData.status == -1) {
return;
}
$('.myplugin-form-container').html(output);
});
</script>
Elgg使用requirejs進行依賴項加載。 您不能僅僅拋出require inline並期望它能工作。 您可以嘗試:
require(['elgg/Ajax'], Ajax => {
var ajax = new Ajax();
ajax.view('developers/ajax_demo.html').then(body => {
console.log('RESULT', body)
})
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.