Welcome Guest, Not a member yet? Register   Sign In
CI + mootools + ajax (actually works)
#1

[eluser]mr_coffee[/eluser]
Yeah I saw some answers for this floating around. But none suited very SIMPLE needs. I found the following on some post on something or another but lack the patience to look it up again. The poster mention "extending" the input library with the following:

Code:
function isAjax() {
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest");
    }

Which to me translated as "add this to the bottom of ci/libraries/input.php and re-upload".

Now in your controllers, you will now have the option to say if isAjax() do this... otherwise do something else. I'd say that something else is the default behavior which is to load the view for each item on the page... whereas if it was an Ajax call... instead of "viewing" navigation, the page layout, the title, etc... you're just "viewing" the one element on the page to be updated. I'll give you this example of actual code I am using:

Code:
function work() {
        if($this->input->isAjax()) {
            $this->load->view('work');            
        } else {
            $data['title'] = "Where I live and work";
            $this->load->view('title',$data);
            $this->load->view('scripts');
            $this->load->view('header',$data);
            $this->load->view('navigation');
            $this->load->view('work');
            $this->load->view('footer');
        }
    }

This works perfectly and as expected. I'll need to - however - add some javascript to update the <title> of the page and the text on the page that shows the title (fourth line in the else portion). Such a SIMPLE answer... reading all these "answers" about trying to re-invent the wheel was giving me a headache. Please repost this enough times that those posts will be trumped in the search engine by this easy working answer.

Contention: you CANNOT USE the safe_email() function on an ajax requested page. It utilizes the javascript d0cument.wr1t3 and that will break everything. Expect an "Operation Aborted" error thrown by IE and a white page that never finishes load in any other browser. Anyway, it will be messy. You could set evalScripts to false and kill the error, but you won't see your e-mail link either. There may be more things you can't use, but that's the one I noticed right away. NO DOCUMENT.WRITEs!


Now for my question: why is it that Opera doesn't display Ajax loaded content inside the specified div? This isn't a CI question, I was just hoping someone had a work-around for that, I'm coming up empty everywhere else. (ps... downloaded the DOM snapshot plugin for Opera: the code is perfect. Tells me the visual rendering should match up, but visually, my ajax requested pages are not displaying within the div I specified, even though by the DOM snapshot: they should be)

Now for my CI question: has anyone successfully written some sort of helper/library/class/ANYTHING that would handle an Ajax "history". Like along with my "$this->load->view('work');" I should have a line saying "$this->history->updateaddressbar('info/work'); $this->history->addclick();" or something like that so that basic back/forward/bookmark/reload functions would be restored. I was playing with something that worked "ok" in mootools, but it was kind of a hassle. I'm not really wanting to test what happens if I start adding hashes to the address bar either while CI is running. I don't expect positive results. I also already know the aforementioned history manager crashed and burned in Opera as well as the basic ajax calls. Strange... I was under the impression Opera allowed MORE things to work, not fewer. Whatever. If you're aware of a history addon thing, I'd like to know.

thanks much.




Theme © iAndrew 2016 - Forum software by © MyBB