[CJAX] ajax won't work when called from any method other than index() in my application/controllers controller |
[eluser]salim.imani[/eluser]
Hello, I've been trying to use Cjax Framework while still preserving the codeigniter call structure in my project For instance, I want to use /ajax/ajxctrl/ajaxmthd to call controller "ajaxctrl" located in application/response only when i need a json reponse, e.g. for autocomplete purposes, and keep using application/controllers/ when I want to display my views, not having to switch regularly between urls like http://localhost/CIproject/ajax/ctrl/mthd and http://localhost/CIproject/controller/method and having frontend controllers split between two locations. For that I've used require_once(FCPATH.'ajaxfw.php'); in my frontend controller I am experiencing some troubles, I hope you'll be able to help me : In my project, I have "regular" controllers (to call the view) in the "application/controllers" folder, and the controllers for ajax in "application/response" In my controller, I've noticed that when I put the actions in the index() function, ajax works and I see the contents (although it behaves strangely, since it doesn't work all the time and sometimes one or two clicks on "refresh" do the trick). But when I put my actions in another function (eg. "showAutocomplete()") nothing happens except that I see the input field. Basically it looks like this : /application/controllers/ ...........frontend.php /application/views/ ...........myview.php /application/response/ ...........autocompdata.php ======== frontend.php ========== Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ======== myview.php ========== Code: <html> ======= autocompdata.php ======= Code: <?php So I call my view from the frontend controller like this : "http://localhost/myproject/frontend/showAutocomplete" It shows me the input field, but nothing happens when I type in it. No ajax works : I've tried with success messages, still nothing shows. If I rename showAutocomplete() into index() and call it like this : "http://localhost/myproject/frontend/" it works just fine, autocomplete, success message, and all. (Although I sometimes need to navigate to "http://localhost/myproject/ajax/autocompdata/update" and back to "http://localhost/myproject/frontend/" before it works for the first time, like with some sort of off/on switch) I know it is quite a strange behaviour, is there something I am doing wrong ? The strangest part is that whether it works or not depends on whether I call my main function "index" or something else. Thank you in advance for the help ! And sorry for the very long post, it was difficult to explain my situation clearly... Salim
|
Welcome Guest, Not a member yet? Register Sign In |