From cd0869064650d17d514a7b78c8ee11061d475de4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Jun 2017 12:42:06 +0200 Subject: [PATCH] Fix ajax search product that return bad json response --- htdocs/product/ajax/products.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/htdocs/product/ajax/products.php b/htdocs/product/ajax/products.php index 0510299fbd7..15541016963 100644 --- a/htdocs/product/ajax/products.php +++ b/htdocs/product/ajax/products.php @@ -160,7 +160,7 @@ if (! empty($action) && $action == 'fetch' && ! empty($id)) } echo json_encode($outjson); -} +} else { require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php'; @@ -171,17 +171,23 @@ else top_httphead(); if (empty($htmlname)) - return; + { + print json_encode(array()); + return; + } $match = preg_grep('/(' . $htmlname . '[0-9]+)/', array_keys($_GET)); sort($match); $idprod = (! empty($match[0]) ? $match[0] : ''); - - if (! GETPOST($htmlname) && ! GETPOST($idprod)) - return; - // When used from jQuery, the search term is added as GET param "term". + if (GETPOST($htmlname) == '' && ! GETPOST($idprod)) + { + print json_encode(array()); + return; + } + + // When used from jQuery, the search term is added as GET param "term". $searchkey = (GETPOST($idprod) ? GETPOST($idprod) : (GETPOST($htmlname) ? GETPOST($htmlname) : '')); $form = new Form($db);