如何将数据从HTML表单传递到处理AJAX调用的JavaScript文件?
submission_form.php
<?php echo elgg_view("input/file", array("name" => "icon", "class" => "icon")); ?>
<p>
<?= elgg_view('input/text', ["name" => 'title', "class" => "title"]); ?>
</p>
submit.js
function myajax_function(){
var Ajax = require('elgg/Ajax');
var ajax = new Ajax();
ajax.action('service_comments/add_service_comment', {
data: {
picture: 1,
description: 2
},
}).done(function (output, statusText, jqXHR) {
if (jqXHR.AjaxData.status == -1) {
return;
}
alert(output.sum);
alert(output.product);
});
}
操作文件: submission_form.php
// Not working
$title = get_input('title');
// I'm not sure how to go about extracting the file from input/file and text from input/text
提前谢谢大家。
我正在使用Elgg版本2.X,并关注this tutorial: Ajax Actions,但我认为这将是标准化的(从HTML到Javascript到PHP的AJAX持久性数据交换)
答案 0 :(得分:1)
在表单标记中添加一个类或ID。
EditText
然后在你的JS文件中
echo elgg_view_form('submission_form', array('class' => 'elgg-form-submission_form'), array());