AJAX Request

edited March 2011 in Modules
hey. me again! :)

I've created my own module. Everything works fine.
In my models folder, i hav an myapp_categories_model.php.

in this model, there are several input elements. one of them is a select item. now i want to add an event to this select item, which will load some other database entries, on change. i've added an JS Controller and the right function.

var path = jqx.config.fuelPath + '/myapp/categories/' $.post(path, {id:$('#id').val() }, function(html){ });

How can i manage a right Ajax request? Do i need a new controller?

Comments

  • edited 8:52AM
    Yes. You will need to setup a controller to handle that. Take a look at "advanced modules" which allows you to setup your own controllers, models, views, etc.
    http://www.getfuelcms.com/user_guide/modules/advanced
  • edited 8:52AM
    fyi: i've created in my module/controllers an ajax.php which extends the fuel_base_controller. to make the hole stuff flexible, i added to the index() method a case statement which checks the request and redirects the request to the required method.

    thank you. And hey: FUEL IS AWESOME!!
  • edited 8:52AM
    Great! Glad to hear you got it working.
  • edited 8:52AM
    If you can share that code for ajax class or the php file and what you did that would be great. I am starting a new application and I will need to work with ajax a lot.
  • edited October 2011
    As an FYI, there is now a method that allows you to make requests on the controller and it will look for model method with a prefix starting with "ajax_". For example:
    $.get('my_module/ajax/my_method', {limit: 5}, function(html){ console.log(html); }
    Would map to a method on you my_module's model of "ajax_my_method()". Arguments can be passed to the method as an array. You can pass parameters via ajax with the get object parameters (e.g. {limit: 5}).
  • edited 8:52AM
    the only thing i wonder, if the profiling is turn on, how to disable it for ajax call ... or else your return result is follow by all those profiling data.
Sign In or Register to comment.