Get category in JSON format via AJAX

More
7 years 6 months ago #67738 by MikeM
Hi. I want use JS for render page and get all data in JSON format, but a have a trouble.

In ideal i wish see:
Code:
id: id, title:title, catid:catid, link:link, customfield: customfield_data, ...etc

But i get anothe things
I add code in file view.json.php
Code:
if (JRequest::getCmd('rest', 0)) { $array_product = array(); $i = 0; foreach ($items as $item) { $array_product [$i]["id"]= $item->id; $array_product [$i]["title"]= $item->title; $array_product [$i]["catid"]= $item->catid; $array_product [$i]["link"]= JRoute::_(FlexicontentHelperRoute::getItemRoute($item->id, $item->catid)); $array_product [$i]["img"]= $item->fields['field15']->thumbs_src['original'];//img $i++; } $json_product = json_encode($array_product); echo($json_product); exit; }

but i get link not a "shop/6-alias" but only "shop/6"
i dont get image - i get null

Please help me to cudtomize JSON output

Please Log in or Create an account to join the conversation.

More
7 years 6 months ago #67764 by MikeM
i edit my code and now it work
Code:
if (JRequest::getCmd('rest', 0)) { //$item = reset($items); //$obj->id = $item->id; //$obj->title = $item->title; //echo @json_encode($obj); $result_product = $items;/*your mysql query here*/ $array_product = array(); $i = 0; foreach ($result_product as $row_product) { $array_product [$i]["id"]= $row_product->id; $array_product [$i]["title"]= $row_product->title; $array_product [$i]["catid"]= $row_product->catid; $array_product [$i]["link"]= JRoute::_(FlexicontentHelperRoute::getItemRoute($row_product->slug, $row_product->categoryslug, 0, $row_product)); FlexicontentFields::getFieldDisplay($row_product, "field15"); $array_product [$i]["img"]= $row_product->fields['field15']->{"display_medium_src"}; $i++; } //you can encode the array to json if you want to send it to an ajax call $json_product = json_encode($array_product); echo($json_product); exit; }

I get only i needed fields/
But another question - how to cache strongly this output to descrease server work?

Please Log in or Create an account to join the conversation.

More
7 years 6 months ago #67768 by ggppdk
Hello

Did you try enabling Joomla 's View caching

I mean conservative / progressive caching ?

it should work the same way that it work for
format=html

-- caching is done at the
display()
of the frontend controller and it does not exclude format=json from caching
so it should work


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.332 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline