Ajax tabs - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Ajax tabs (/showthread.php?tid=12288) |
Ajax tabs - El Forum - 10-13-2008 [eluser]crumpet[/eluser] Hi, I am trying to create a product view page with tabs for comments, related products, etc. I want these tabs to load through ajax when you click the buttons. My first instinct was to have ajax post to a seperate function for each tab and have that function reply with a view file which the js displays. I can't seem to get this to work with json. Code: $return['view'] = $this->load->view('front/modules/resources/resource_view/additional/comments'); Code: {"view":null}whats up Thanks Ajax tabs - El Forum - 10-13-2008 [eluser]Pascal Kriete[/eluser] It's because you're not returning the view file. By default it's added to the CI output 'buffer'. Code: $return['view'] = $this->load->view('front/modules/resources/resource_view/additional/comments', '', TRUE); I don't really see why you have to do this though. If the view is the only thing you're sending, just echo it. Code: // php Ajax tabs - El Forum - 10-13-2008 [eluser]crumpet[/eluser] I realized that error about 30 seconds after i posted and felt stupid. But thats a good point about the object. I've changed it now to be like how you have suggested. Can you comment on whether its better to have php assemble the view or js... for instance one tab is called comments so I could have it respond with an array of comments and make jquery format and display them. Right now I have php do the formatting so jquery can just do $('#display').html(response). Ajax tabs - El Forum - 10-13-2008 [eluser]Pascal Kriete[/eluser] I would definitely assemble them with PHP. If you decide to change the formating in a year or two it'll be a lot easier to work out what's going on. Ajax tabs - El Forum - 10-13-2008 [eluser]Colin Williams[/eluser] As a rule I would almost always have Ajax calls return formatted code that way you can just hop in and edit the view file to change the markup. I would only return JSON if you are meaning to serve requests from external servers, in which case you are probably just returning data straight from a model function. |