Welcome Guest, Not a member yet? Register   Sign In
Fatal error in relation to Javascript
#1

[eluser]russ_kern[/eluser]
I'm hoping I can explain this well...

Within my view pages, I have a div tag that I am using a piece of Javascript on to swap out its contents based on on which link a user clicks.

My Javascript and the files that it calls to place inside this div all reside in folders OUTSIDE of the System folder.

When I call a function from one of these loaded files , I get the following error on the page it loads into:

"Fatal error: Using $this when not in object context in /home/supercha/dev/assets/builderscripts/contenta.php on line 100"

Would anyone have ideas why I'm getting this error?

It is worth noting that when I call this same function from within the page in my View file, It displays correctly - so the script itsself works.

Russ
#2

[eluser]Mark Croxton[/eluser]
You can't just load a view file with js and expect that CI will parse it in the current context. You'll have to load a controller method and have that output a view partial.
#3

[eluser]Unknown[/eluser]
Hi, I had the same problem and now it works. Puhh.. :-)
Thanks Mark.

Greeting

------------------
George Gina Lucy Tasche - Taschen die freaky sind
Slivovic Obstbrand - Slivovic auch Sljivovica
#4

[eluser]russ_kern[/eluser]
Thanks for the response Mark...

I've played around with this a bit but thus far have had no luck and am wondering how someone might suggest approaching this?

Basicly, my page has 6 regions in it, each with the same selection of options to choose from. When you click on one of the options in each area, I insert the content of an externally called page into the DIV tag in that area via Javascript.

I try to keep any links (such as css, images, javascript and .. these content files) in a directory outside of the CI system directory.

I'm trying to create a controller for each of these externally called pages and then call the controller from the javascript rather than the actual page as I was currently doing.

I'm not having much luck getting the content to load into my div tag now...

I'm sure the javascript I'm using is not new to most people here, just having difficulty integrating it.

Hope I've explained myself well enough for someone to be able to point me in the right direction (I really should only need a nudge... not the actual solution)

Russ
#5

[eluser]danmontgomery[/eluser]
Post code.
#6

[eluser]Mark Croxton[/eluser]
Use ajax? In jquery it's as easy as:

Code:
$('#mydiv').load('controller/method');
#7

[eluser]russ_kern[/eluser]
That code is what I'm using

Code:
function loadContenta(id) {
            $("#regiona").load("/builder/contenta/"+id+"");
        }

        function loadContentb(id) {
            $("#regionb").load("/builder/contentb/"+id+"");
        }

        function loadContentc(id) {
            $("#regionc").load("/builder/contentc/"+id+"");
        }

        function loadContentd(id) {
            $("#regiond").load("/builder/contentd/"+id+"");
        }
        function loadContente(id) {
            $("#regione").load("/builder/contente/"+id+"");
        }
        function loadContentf(id) {
            $("#regionf").load("/builder/contentf/"+id+"");
        }

Except that in addition, I'm passing an id# of the selection which then calls the proper case statement in the controller (i.e. "contenta")

So this should work... I'll keep working with it, I'm likely missing something simple then. Good to know I'm on the correct track though.

Thanks.

Russ
#8

[eluser]Clifford James[/eluser]
I always use site_url for urls even in java-script
Code:
function loadContenta(id) {
    $("#regiona").load('<?=site_url('builder/contenta')?>/'+id);
}
#9

[eluser]danmontgomery[/eluser]
The error is pretty straight forward, you're calling $this outside of an object context, so where is that file being loaded? What's in it? If you're trying to interact with CI through javascript, you still need to go through the controller->method route, you can't load files from assets directly. I'm not sure if you are based on what you've posted, but you can't Tongue
#10

[eluser]russ_kern[/eluser]
[quote author="noctrum" date="1282160009"]... you can't load files from assets directly. I'm not sure if you are based on what you've posted, but you can't Tongue[/quote]

I was... but now I'm not.

getting closer... LOL.. If I could just work through this un-interrupted it would probably help!

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB