javascript - how to set php array from the json ajax response -


Category Show list. After clicking on the category, we have listed products by category, when I clicked the category, get_category_products fucntion, "unit": {"name": "clock", "unique_pres": "430.00"}, { "Name": "clock", "unit_pres": "250.00" and back to Jason output

 }] function: (category) {$. Ajax ({type: 'POST', url: "get_category_products.php", async: true, data: 'category =' + category, cache: wrong, success: work (data) {warning (data);}}); }   

product list code

   & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> & Lt ;? php $ products_list [$ pr1] - & gt; Name;? & Gt; & Lt; / Td> & Lt; Td> & Lt ;? php echo $ products_list [$ pr1] - & gt; Unit_pris ;? & Gt; & Lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; & Lt; / TD & gt; & Lt ;? Php if ($ count% 3 == 0) {? & Gt; & Lt; / Tr & gt; & Lt; Tr & gt; & Lt ;? Php}? & Gt; & Lt ;? Php $ count ++; }? & Gt; & Lt; / Table & gt; & Lt; / Div & gt;   

How to decode json output and set to php array ($ products_list), how to display the product by category using the above code.

Add data type: 'jason' in AJAX call, and jQuery auto The format will decode it for you.

  $ Ajax ({type: 'POST', url: "get_category_products.php", async: true, data: {class: category}, datatype: 'json', // ******* cache: wrong, success: Work (data) {warning (data);}});   

I always recommend passing an object as a data option, which allows jQuery to encrypt it for you (it < Instead of the code> encodeURLComponent param = value string , correctly encodes special characters)

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -