massi4 Posted May 6, 2015 Share Posted May 6, 2015 salut j'ai un formulaire dans mon module en back office. j'ai 2 balise select et je voudrais que le 2eme select affiche des valeurs en fonction du 1er select voici mon fichier qui devrait envoyer et recevoire les donnees adminvitrine.php <?php //die(); //include(_PS_ROOT_DIR_.'\init.php'); //include(_PS_ROOT_DIR_.'\config\config.inc.php'); class AdminVitrineController extends ModuleAdminController { public function __construct() { $this->bootstrap = true; parent::__construct(); } public function initContent() { if (!defined('_PS_ADMIN_DIR_')) define('_PS_ADMIN_DIR_', getcwd()); //echo getcwd(); //include(_PS_ADMIN_DIR_.'/../config/config.inc.php'); /* Getting cookie or logout */ //require_once(_PS_ADMIN_DIR_.'/init.php'); $products_partials = Product::getProducts(1, 0, 0, 'id_product', 'DESC' ); $adhesif = AdhesifModel::findAll(); //$subcategoryImages = SubCategoryImagesModel::findAll(); $Images = ImageModel::findAll(); $subcategory = SubCategoryModel::findAll(); $products = Product::getProductsProperties(1, $products_partials); foreach ($products as $key => $product) { $cover = Product::getCover($product['id_product']); $products[$key]["id_image"] = $cover["id_image"]; } $json = array(); if(tools::getValue('q')) { $id = htmlentities(intval(tools::getValue('q'))); // requête qui récupère les images selon la sous categorie $json = SubCategoryImagesModel::find($id); $this->context->smarty->assign('subcategoryImages',$json); echo json_encode($json); } $this->context->smarty->assign('products',$products); $this->context->smarty->assign('adhesifs',$adhesif); //$this->context->smarty->assign('subcategoryImages',$subcategoryImages); $this->context->smarty->assign('subcategories',$subcategory); $this->context->smarty->assign('img','http://localhost/prestashop/img/vitrine/'); parent::initContent(); } } et voici le ficjier JS $subcategory.on('change', function() { var val = $(this).val(); // on récupère la valeur des souscategories if(val != '') { $image.empty(); // on vide la liste des images alert(val); $.ajax({ url: 'http://localhost/prestashop/modules/vitrine/controllers/admin/adminvitrine.php', data: 'id_subcategory='+ val, // on envoie $_GET['id_subcategory'] dataType: 'json', success: function(json) { $.each(json, function(index, value) { $image.append('<option value="'+ index +'">'+ value +'</option>'); }); } }); } }); merci Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now