I am working on an e-commerce project for practice and right now I am building product filters. So I have three files
-
catalogue.php
- It basically shows all the products.
product filters on left and displays products on right. When user checks a box then AJAX call is made.
-
productsfilter.js
-
It contains Javascript and AJAX calls.
var themearray = new Array(); $('input[name="tcheck"]:checked').each(function(){ themearray.push($(this).val()); }); if(themearray=='') $('.spanbrandcls').css('visibility','hidden'); var theme_checklist = "&tcheck="+themearray; var main_string = theme_checklist; main_string = main_string.substring(1, main_string.length) $.ajax({ type: "POST", url: "mod/product_filter.php", data: main_string, cache: false, success: function(html){ replyVal = JSON.parse(myAjax.responseText); alert(replyVal); } });
-
-
product_filter.php
-
It is the PHP script called by the AJAX call.
$tcheck = $objForm->getPost('tcheck'); if(!empty($tcheck)) { if(strstr($tcheck,',')) { $data1 = explode(',',$tcheck); $tarray = array(); foreach($data1 as $t) { $tarray[] = "adv.attribute_deterministic_id = $t"; } $WHERE[] = '('.implode(' OR ',$tarray).')'; } else { $WHERE[] = '(adv.attribute_deterministic_id = '.$tcheck.')'; } } $w = implode(' AND ',$WHERE); if(!empty($w)) { $w = 'WHERE '.$w; } $results = $objCatalogue->getResults($w); echo json_encode($results);
-
So product_filter.php returns an array of product_id
s retrieved from the database and gives it back to AJAX. Now the problem is: that array of product ids I got from AJAX call, how do I use it in catalogue.php?
As I got {["product_id" : "1"]}
from product_filter.php, I want to use this id in catalogue.php and find the related attributes and display the product details.
How can I pass this array to my catalogue.php page so that it can use this array and call further PHP functions on it?
If the question is unclear then kindly say so, and I will try to explain it as clearly as I can. Help would be much appreciated.