logo
down
shadow

Ajax in a Joomla 3.x component's view


Ajax in a Joomla 3.x component's view

By : Eric Arean
Date : November 22 2020, 10:56 AM
this one helps. @Torreto and @GDP for your participation.
I finally kept on creating a task in the main controller exchanging with the database directly, so without using any model. I think it should exist a better and cleaner way to code this ajax call, so I'm open to any advice for further improvement.
code :
<script type="text/javascript">
  jQuery(document).ready(function () {
    jQuery('#main_search_request').keyup(function() {
      var request_content = jQuery(this).val();
      jQuery.get(
        // Specify the server URL and the $_GET datas to send
        'index.php?option=com_jomcity&task=searchVenues&format=json',
        { search: request_content },
        // The server will respond with some data encoded in JSON
        function(data){
          // Clean the #result div between two search results
          jQuery('#results').html('');
          // Read and display each objects returned in the json response
          for (var i = 0; i < data.length; i++) {
            var venue = data[i];
            jQuery('#results').append(
              '<div class="grid-item">' +
                '<a href="#">' +
                  '<img src="http://placekitten.com/g/80/80" alt="">' +
                  '<div>' +
                    '<div>' +
                      '<h3>'+venue.en_name+'</h3>' +
                      '<span>* * * * *</span>' +
                    '</div>' +
                    '<div>Short descrption</div>' +
                  '</div>' +
                '</a>' +
              '</div>'
            );
          }
        }
      );
    });
  });
</script>
class JomCityController extends JControllerLegacy
{
    /**
     * Search in all the venues
     * @return string The message to be displayed to the user
     */
    public function searchVenues() {
        if (isset($_GET['search'])) {
            // Get a db connection
            $db = JFactory::getDBO();
            // Create a new query object
            $query = $db->getQuery(true);
            // Select all records from the jomcity_venues_items table
            // Where the name or the description correspond to the user's search keywords
            // Order it by the en_score field
            $query
                ->select('*')
                ->from('#__jomcity_venues_items')
                ->where('`local_name` like "%'.$_GET['search'].'%" OR `en_name` like "%'.$_GET['search'].'%" OR `description` like "%'.$_GET['search'].'%"')
                ->order('en_name ASC');
            // Reset the query using our newly populated query object
            $db->setQuery((string)$query);
            // Load the results as a list of stdClass objects.
            $this->venues = $db->loadObjectList();
        }
        echo json_encode($this->venues);
    }
}


Share : facebook icon twitter icon
how to use Jquery AJAX in Joomla Components?

how to use Jquery AJAX in Joomla Components?


By : user2105406
Date : March 29 2020, 07:55 AM
I wish this helpful for you All front end code should be in your tmpl, so your Ajax stuff should be in there too. Check this tutorial out on how to make MVC components for Joomla http://www.joomladevuser.com/tutorials/components (deadlink).
Passing data from joomla view to joomla template file in joomla 1.7

Passing data from joomla view to joomla template file in joomla 1.7


By : user3806888
Date : March 29 2020, 07:55 AM
around this issue I want to know how can I pass data from joomla view to joomla template. How can I pass multiple variables? , We can pass view data to template by using:
code :
$var1="Some string";
$this->assignRef('var1',$var1);
echo $this->var1;
How to add a new view (and also a new Menu Item Type) to existing joomla 2.5 components?

How to add a new view (and also a new Menu Item Type) to existing joomla 2.5 components?


By : Juan G. Sanchez
Date : March 29 2020, 07:55 AM
wish of those help Yes You can create a new view.
Its simple just copy any of the view (category,blog) from your com_content.
code :
Step 1

view.html.php
tmpl
   your layout names(default.php)
xml file.
Also remember to change the class name of the view.html.php

Step 2

Add a controller file (just make a copy of existing one category or blog)
Controller name must be your new view folder name.
Also remember to change the class name of the controller

step 3 

add a model file for your new view (same make copy of any existing)
remember to change the class name and file name should be view folder name.
How can I ajax within a joomla component's view (k2) to access & update user profile data from the database?

How can I ajax within a joomla component's view (k2) to access & update user profile data from the database?


By : SQL Bro
Date : March 29 2020, 07:55 AM
Hope this helps You should write a component to handle the ajax calls, or at the very least add a controller with the tasks you need, i.e. if you're trying to get some json back:
code :
{user:'paul', custom_field_1:'yes and no'}
function getInfo() {
  // return the json
  echo json_encode($myResultArray);
  exit; // this will make sure you don't get the template etc.
}
http://example.com/index.php?option=com_your_component&task=getInfo&format=json
PHP/Joomla - Sending html output to a jQuery AJAX from a Joomla MVC controller

PHP/Joomla - Sending html output to a jQuery AJAX from a Joomla MVC controller


By : user6128326
Date : March 29 2020, 07:55 AM
Does that help it should be sufficient to add &format=raw to the url, that will instruct Joomla! to pass through the component output and not add the whole template/page/modules around it.
However while die() is not nice, simply calling exit in the controller will achieve just the same. Sometimes, when you have SEF enabled and a router.php parser based on the number of parameters this can be the best option.
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org