Welcome Guest, Not a member yet? Register   Sign In
JQuery and Ajax Issue
#41

[eluser]Bendude[/eluser]
Yer that is the issue, WOW it took some finding. I owe you a few beers to say the least. Ill just do some searching to try and fix my .htaccess issue and report back with the fix.

One more quick question, what is the best way to pass data to the jquery function?

before when i was displaying the data i was able to do onclick="filter(<?php echo $id; ?&gtWink" etc...
#42

[eluser]alboyd[/eluser]
Lol well i'm not sure. But I gather you mean how to pass data from the anchor to jquery not from controller to jquery...

So the way I have done it a lot is using class and id lol.. probably quite bad but hell it works!

for example:
Code:
<a href="#" id="view_item" class="item_&lt;?php echo $item_id;?&gt;">Item &lt;?php echo $item_name;?&gt;</a>

Then in JQuery:
Code:
$("a#view_item").click(function() {
    var item_id_str = $(this).attr("class");

// post it to controller as item_id_str : item_id_str
});

You could also use title I guess. I don't think anyone else on this forum is bothering reading this thread - but if they are I would be interested to see how other people do it!

In controller if I need the ID that has been passed through (item_10):
Code:
$item_id_str = $this->input->post('item_id_str');

list($blah, $item_id) = split('_', $item_id_str);

// Do stuff with your new $item_id value.... :)

EDIT: In most cases it will be the other way around - you will have a list of anchors with id's and therefore the class should be used for the click trigger ie; class = "view_item" and the ID should be the item_id
#43

[eluser]Bendude[/eluser]
well actually i had used it in the class name before but i was hoping someone would provide a better method.

Anyways that should do fine.

Thanks for all the help, hopefully i can repay you someday...
#44

[eluser]alboyd[/eluser]
edited my post fyi
#45

[eluser]Ramania[/eluser]
about loading the view inside the constructor, it's not a bad idea at all, it's a very good idea and it actually saves you the trouble of loading multiple headers and make your code cleaner, i'm sorry i didn't follow you guys carefully through the following posts, but i just wanted to share my opinion, because i've tried the view loader, and i've tried loading the header.php view in the constructor, and both works same yet the constructor method is a better practice i guess since it'll apply the header to virtually every function within the class.
#46

[eluser]alboyd[/eluser]
[quote author="Ramania" date="1261098544"]... and both works same yet the constructor method is a better practice i guess since it'll apply the header to virtually every function within the class.[/quote]

I'm not sure I understand what you are saying?

But if you are referring to some HTML/PHP for top of a page view then I guess it would be fine except that when you have a situation where you want a different top section for a particular view which is generated from the same controller.

Also you are most likely to want this flexibility for the rest of the view (variable content, variable menus, variable footers, sidebars whatever) - so why not keep them all configured in one spot (a view loader or main view) rather than one bit in the controller constructor, and the rest scattered around whereever else you are proposing?

Just my 2c... but whatever works for you I guess!
#47

[eluser]Ramania[/eluser]
[quote author="alboyd" date="1261115820"]except that when you have a situation where you want a different top section for a particular view which is generated from the same controller.
[/quote]

i guess i agree with you on that, but i am sure there is a way that might be yet more effective than both ways Smile




Theme © iAndrew 2016 - Forum software by © MyBB