Jump to content

Data show using Jquery Ajax


shovonbugs

Recommended Posts

I'm trying to retrive data using jquery Ajax, Here is my code....

 

Problem is when I select value from drop down list the selected value posted successfully and I checked in browser console that the value is passing and show but cannot retrive in template file that I'm trying to get after query execute. Also I attached the browser console file.

 

Please help me someone...

 

Template File (content.tpl)

________________________

{literal}
<script>
  $("#monthID").change(function() {
      var showJsMonth = ($(this).val());
            $.ajax({
                type: 'POST',
                async: true,
                cache: false,
                data : {
                    ajax : true,
                    controller : 'AdminHome',
                    token : '{token}',
                    monthSM : showJsMonth,
                    action : 'showMonthresult'
                },
                url: 'ajax-tab.php',
                dataType : 'JSON',
                success: function(data) {
               
                      $(".showMonth").html(data[2].id_address); /* Not working */

                },
                error: function(data, textStatus, errorThrown)
                {
                    jAlert("TECHNICAL ERROR:");
                }
            });
  });
</script>
{/literal}

-----------------------------------------------------------------------------

Controller Page(AdminHomeController.php)

________________________________________________

public function ajaxProcessShowMonthresult()
    {  
    $smarty = $this->context->smarty;
    $monthSM=Tools::getValue('monthSM');
    $smarty->assign('showMonth', ObjectModel::getRefrigOrdersMonth($monthSM));

    }

________________________________________________

Model File(ObjectModel.php)

________________________________________________

public function getRefrigOrdersMonth($monthSM){
    $monthSMs =  pSQL($monthSM);
    $a1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
        SELECT '._DB_PREFIX_.'address.`id_address`,'._DB_PREFIX_.'address.`address1`, '._DB_PREFIX_.'address.`address2`, '._DB_PREFIX_.'address.`postcode`, '._DB_PREFIX_.'address.`city`, '._DB_PREFIX_.'orders.`id_customer`, '._DB_PREFIX_.'orders.`id_order`, '._DB_PREFIX_.'address.`company`, '._DB_PREFIX_.'customer.`firstname`, '._DB_PREFIX_.'customer.`lastname`, '._DB_PREFIX_.'order_detail.`product_quantity`, '._DB_PREFIX_.'order_detail.`product_name`, '._DB_PREFIX_.'manufacturer.`name` FROM `'._DB_PREFIX_.'orders`
                LEFT JOIN `'._DB_PREFIX_.'order_detail`
                ON `'._DB_PREFIX_.'orders`.id_order = `'._DB_PREFIX_.'order_detail`.id_order
                LEFT JOIN `'._DB_PREFIX_.'customer`
                ON `'._DB_PREFIX_.'customer`.id_customer = `'._DB_PREFIX_.'orders`.id_customer
                LEFT JOIN `'._DB_PREFIX_.'address`
                ON `'._DB_PREFIX_.'address`.id_customer = `'._DB_PREFIX_.'customer`.id_customer
                
                LEFT JOIN `'._DB_PREFIX_.'manufacturer`
                ON `'._DB_PREFIX_.'address`.address1 = `'._DB_PREFIX_.'manufacturer`.id_manufacturer
                
                WHERE `'._DB_PREFIX_.'order_detail`.product_name LIKE \'%'.$monthSMs.'%\'
                
                ORDER BY `'._DB_PREFIX_.'orders`.id_order
        
        ' );
            
        for ($z = 0; $z < count($a1); $z++){
        echo $firstname= $a1[$z][id_address];
        $result[] = array($firstname);    
        }
        return ($result);
}

 

--------------------------------------------------------------------------------------------

post-713144-0-90466600-1380770868_thumb.jpg

Link to comment
Share on other sites

Now I'm getting datas but problem is how do I show multiples data in ajax template, please the attached file..

 

Here is my updated code

 

content.tpl

---------------------------------------------

{literal}
<script>
  $("#monthID").change(function() {
      var showJsMonth = ($(this).val());
            $.ajax({
                type: 'POST',
                async: true,
                cache: false,
                data : {
                    ajax : 1,
                    controller : 'AdminHome',
                    token : '{token}',
                    monthSM : showJsMonth,
                    action : 'showMonthresult'
                },
                url: 'ajax-tab.php',
                dataType : 'JSON',
                success: function(msg)
                        {
                            if (msg)
                            {
                                
                                var infos = msg.infos.split('_');
                                $('.showMonth').html(infos[0] + infos[1] + infos[2]);

                                
                            }
                            
                        },
                error: function(msg, textStatus, errorThrown)
                {
                    jAlert("TECHNICAL ERROR:");
                }
            });
  });
</script>
{/literal}

-------------------------

AdminhomeController.php

------------------------------------------

public function ajaxProcessShowMonthresult()
    {  

    if (Tools::getValue('monthSM'))
        {
            $monthSM = pSQL(Tools::getValue('monthSM'));
            $monthSMResult = ObjectModel::getRefrigOrdersMonth($monthSM);
            if (!empty($monthSMResult))
            {
                foreach($monthSMResult as $monthSMR){
                //$monthSMResult = $monthSMResult['0'];
                echo Tools::jsonEncode(array('infos' => pSQL($monthSMR['firstname']).'_'.pSQL($monthSMR['lastname']).'_'.pSQL($monthSMR['id_address'])));
                }
            }
        }
        die;
        
        
    }

------------------------------

ObjectModel.php

-----------------------------

public function getRefrigOrdersMonth($monthSM){
    $monthSMs =  pSQL($monthSM);
    $sql = '
        SELECT '._DB_PREFIX_.'address.`id_address`,'._DB_PREFIX_.'address.`address1`, '._DB_PREFIX_.'address.`address2`, '._DB_PREFIX_.'address.`postcode`, '._DB_PREFIX_.'address.`city`, '._DB_PREFIX_.'orders.`id_customer`, '._DB_PREFIX_.'orders.`id_order`, '._DB_PREFIX_.'address.`company`, '._DB_PREFIX_.'customer.`firstname`, '._DB_PREFIX_.'customer.`lastname`, '._DB_PREFIX_.'order_detail.`product_quantity`, '._DB_PREFIX_.'order_detail.`product_name`, '._DB_PREFIX_.'manufacturer.`name` FROM `'._DB_PREFIX_.'orders`
                LEFT JOIN `'._DB_PREFIX_.'order_detail`
                ON `'._DB_PREFIX_.'orders`.id_order = `'._DB_PREFIX_.'order_detail`.id_order
                LEFT JOIN `'._DB_PREFIX_.'customer`
                ON `'._DB_PREFIX_.'customer`.id_customer = `'._DB_PREFIX_.'orders`.id_customer
                LEFT JOIN `'._DB_PREFIX_.'address`
                ON `'._DB_PREFIX_.'address`.id_customer = `'._DB_PREFIX_.'customer`.id_customer
                
                LEFT JOIN `'._DB_PREFIX_.'manufacturer`
                ON `'._DB_PREFIX_.'address`.address1 = `'._DB_PREFIX_.'manufacturer`.id_manufacturer
                
                WHERE `'._DB_PREFIX_.'order_detail`.product_name LIKE \'%'.$monthSMs.'%\'
                
                ORDER BY `'._DB_PREFIX_.'orders`.id_order
        
        ';
            
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}

------------------------------------------

post-713144-0-81658200-1380787001_thumb.png

Edited by shovonbugs (see edit history)
Link to comment
Share on other sites

you've got technical error so it mean that you've got probably problem ajax query

you see this part:
 

error: function(msg, textStatus, errorThrown)
                {
                    jAlert("TECHNICAL ERROR:");
                }

it's weirdy mainly because you've got response and HTTP status 200 OK

 

there is no 404 etc. ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...