Welcome Guest, Not a member yet? Register   Sign In
Help with Ajax Autocomplete
#1

[eluser]josebalius[/eluser]
Hey guys, I am fairly new to this library and I was wondering if I could get some assistance on my problem.

Here is the controller:

Code:
class Home extends Controller {

    var $data;
    
    function Home() {
    
        parent::Controller();
        
        // Load custom lib
        $this->load->library ( "ajax" );
        
        // Load db
        $this->load->database();
        
    }

    function get_list() {
        echo "<ul><li>Test</li></ul>";
    }

And here is are two parts of the view (a lot of html that I don't wanna post)

Code:
ALL HTML CODE here
                &lt;?php
                echo $this->ajax->text_field_with_auto_complete('test', array('size' => 20), array('url' => '/home/get_list'));
                ?&gt;

Problem is that when I try it, it doesn't show anything at all, now if I change /home/get_list to "get_list" by itself (invalid URL) then it does work but with a 404 Error of course, so I was wondering why when I provide the correct url it doesn't show anything?

Im I showing my HTML results incorrectly?

Thanks

Jose
#2

[eluser]Pascal Kriete[/eluser]
Code:
$this->load->view('viewname');
#3

[eluser]josebalius[/eluser]
Sorry I forgot to post another part of the controller:

Code:
function index() {
    
        // Generate statistics
        
        // Number of publishers
        $result = $this->db->query ( "SELECT * FROM `publisher`" );
        $this->data['publishers'] = $result->num_rows();
        
        // Number of testers
        $result = $this->db->query ( "SELECT * FROM `tester`" );
        $this->data['testers'] = $result->num_rows();
        
        // Non-active testers
        $result = $this->db->query ( "SELECT * FROM `tester` WHERE `AccountStatus` = '1'" );
        $this->data['nonactive_testers'] = $result->num_rows();
        
        // Testers joined raffles
        
        //Projects
        $result = $this->db->query ( "SELECT * FROM `project`" );
        $this->data['projects'] = $result->num_rows();
        
        // Load the view
        $this->load->view ( "home", $this->data );
        
    }
#4

[eluser]Pascal Kriete[/eluser]
Ah, it seems I missread your first post, as well. Try loading the url helper and doing:
Code:
site_url("home/get_list");
That should generate a valid url.
#5

[eluser]josebalius[/eluser]
Thank you so much! that seemed to work perfectly!
#6

[eluser]josebalius[/eluser]
I was wondering if anyone could tell me, how i can get the input to use in my function?

For example I have

function get_list(), I tried function get_list($input) but and error came up.

nvm, for other learning users: use $_POST['fieldname'];
#7

[eluser]josebalius[/eluser]
Sorry for the third post in a row (is it allowed?) But now I am using the:

Code:
$this->ajax->remote_function('elementforresult', array('url' => '/checkuser/');

On a button however I don't understand how I would be able to set a parameter? For example if I have a form with a field that I want to be send when a user clicks on a special ajax button, how can I make that remote_function grab the value by its ID or something? I just don't know how to call it with the PHP options.
#8

[eluser]Pascal Kriete[/eluser]
I have no clue how to do it with that library, but if it helps, this is how you would do it with regular js using prototype:

In the html head tag:
Code:
function init() {
        $('the_form_id').observe('submit', dostuff);
    }

    function dostuff(event) {
        event.stop();
        var url = 'whatever/whoever/wherever/';

        new Ajax.Request(url, {
            parameters: { name: $F('the_field')},
            method: 'post',
            onComplete: function(truck) {
                $('the_form_id').update('Yay, all done!');
            },
            onCreate: function() {
                $('the_form_id').update('Submitting...');
            }
        });
    }

    document.observe('dom:loaded', init);
#9

[eluser]josebalius[/eluser]
Okay I was able to play around with the ajax code and I have gotten this so far:

Code:
new Ajax.Updater('box', '/view_newsletters/preview',{
method:'post',
evalScripts:true,
parameters:Form.serialize('htmlcontent')

}

);

This is inside a form, which has the "htmlcontent" field.

This was done by using the following php code:

Code:
$this->ajax->remote_function(
array('url' => site_url('/view_newsletters/preview/'),
'update' => 'box',
"parameters" => true,
"submit" => "htmlcontent",
"method" => "post")
);

However my $_POST are coming out blank, no vars what so ever (I am doing a var_dump)

Can anyone help?
#10

[eluser]Greg Aker[/eluser]
If you haven't seen it, check out Derek Allard's video tutorial at: http://video.derekallard.com/

-greg




Theme © iAndrew 2016 - Forum software by © MyBB