Get AJAX/Jquery working in blog tools edit form

Hi,

I am trying to get AJAX/Jquery working in blog tools plugin's edit form... unfortunately unsuccessfully. The schematic:

In start.php I have added:

$url = 'mod/blog_tools/views/default/js/blog_tools/autofill.php';
elgg_register_js('blog_tools', $url);
elgg_register_ajax_view('blog_tools/process'); 

 

In forms/edit.php of the blog_tools plugin:

elgg_load_js('blog_tools');

<select name="source_select" id="source_select" onchange="ajax_update(this)">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>

<div id="result_div"></div>

In autofill.php I have the followings:

function ajax_update(category) {
var value = category.value;
var text = category.options[category.selectedIndex].text;
alert('Value: ' + value + ', and text ' + text);

$.post('process.php', 'select_value: value, select_text: text', function(data) {
$('#result_div').html(data);
});
}

In process.php I have only this:

<?php
if (isset($_POST['select_value'])) {
$value = $_POST['select_value'];
$text = $_POST['select_text'];
echo 'Text: '.$text.', and value: '.$value;
}
?>

 

All a receive from this code is to load the whole page into the <div id="result_div"></div>.

My questions would sound:

1. What can be the problem?
2. Where the process.php should be located?
3. Is the ajax_view properly registered?
4. Should it be loaded at the beginning of the form like the elgg_load_js('blog_tools') is loaded?
5. Can I use elgg functions in process.php?

  • OK, so the first problem was in the autofill.php. It should look like this:

    function ajax_update(category) {
    var value = category.value;
    var text = category.options[category.selectedIndex].text;

    $.post('../../mod/blog_tools/views/default/blog_tools/process.php', { text: text, value: value }, function(data) {
    $('#result_div').html(data);
    });
    }

    Now I am getting back the proper data. 

    TO DO:
    1. How to use elgg functions in process.php?
    2. If I type in the browser the URL of process.php, I can see its content. It is probably not registered properly. How can I fix this?

  • OK, it's me again. I needed to add to process.php an elgg engine igniter. It looks like this:

    require_once(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . "/engine/start.php");

    Now I can use every elgg function, however it takes 10x longer for the server to response, then without the igniter.

    Is there any solution that would not require the ELGG engine to ignite and keep the every function?