How to create a view for an AJAX call?

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
User avatar
fmmarzoa
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 123
Joined: Sun Nov 11, 2007 1:15 pm
Location: Spain
Contact:

How to create a view for an AJAX call?

Post by fmmarzoa » Tue Jan 17, 2012 6:02 pm

Hi,

I need to create a "raw" view for an AJAX call. I rather prefer not to create new controller nor model neither, since I have yet them and can do what the view needs, I just need to do its output in a "raw" format -without joomla template surrounding- so its output may be used to fill an input field on a JavaScript call.

I have many doubts on this issue.

For example, I have created a new view with this structure into my components administrator part:

/views/commentlist
/views/commentlist/tmpl
/views/commentlist/tmpl/list.php
/views/commentlist/view.raw.php

The view also needs to receive an extra parameter when called, so I will pass it on get as article_id.

First question is how to call now that view, i.e., what URI should I use to link it and what I need to implement on my default controller so it uses that view instead of other.

I think the URL may be something like:

/index.php?option=com_lxncom&task=commentlist.list&article_id=3214

But I am not sure about if this is the correct one, and also what controller will call this and what method I need on the controller to handle that request.

TIA,
“The media's the most powerful entity on earth. They have the power to make the innocent guilty and to make the guilty innocent, and that's power. Because they control the minds of the masses.” -- Malcolm X

User avatar
fmmarzoa
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 123
Joined: Sun Nov 11, 2007 1:15 pm
Location: Spain
Contact:

Re: How to create a view for an AJAX call?

Post by fmmarzoa » Tue Jan 17, 2012 6:33 pm

I am getting crazy with this.

It seems like a format=raw parameter is needed for formatting the raw output.

I rather like to use a controller that is called 'comments'. But if I use this link:

/index.php?option=com_lxncom&task=comments.list&format=raw

Then it looks for a controller named comments.raw.php instead of comments.php.

So I tried this other kind of link:

/index.php?option=com_lxncom&controller=comments&task=list&format=raw

And then controller parameter seems to be ignored, and it tries to use the default component controller instead.

So, how can I build a link to use the "comments" controller?

Regards,
“The media's the most powerful entity on earth. They have the power to make the innocent guilty and to make the guilty innocent, and that's power. Because they control the minds of the masses.” -- Malcolm X

guyjeffries99
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Sep 29, 2011 4:05 pm

Re: How to create a view for an AJAX call?

Post by guyjeffries99 » Fri Mar 02, 2012 1:38 pm

Hi

I think what you need for "format=raw" is "tmpl=raw" in the url, for instance:

/index.php?option=com_lxncom&controller=comments&task=list&tmpl=raw

Pocketss
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 105
Joined: Thu Aug 27, 2009 3:07 am
Location: Troy, MI - USA

Re: How to create a view for an AJAX call?

Post by Pocketss » Sun Mar 04, 2012 7:16 am

I should mention I have not tried this, but looking through the code in JController.

try "type=raw" see if that works. You also want to add "tmpl=component" so you only get the component's output instead of modules and such.

User avatar
NachoBrito
Joomla! Apprentice
Joomla! Apprentice
Posts: 37
Joined: Tue Sep 21, 2010 3:35 pm
Location: Madrid (Spain)
Contact:

Re: How to create a view for an AJAX call?

Post by NachoBrito » Sun Mar 04, 2012 8:27 am

Hi,

you don't need to call the controller if you only need to render a view. You could try this:

index.php?option=com_lxncom&view=commentlist&format=raw

and then define your view like this:

/views/commentlist
/views/commentlist/tmpl
/views/commentlist/tmpl/default_raw.php
/views/commentlist/view.raw.php

(I'm writing on the go, beware of typos...)

HTH.
Soporte técnico Joomla en Español: http://www.expertosjoomla.es


Locked

Return to “Joomla! 2.5 Coding”