How to get product data with Javascript, ajax and PHP

Asked

Viewed 69 times

0

Hello, I am unable to bring the product data to the <div id="services"></div>.

I notice when I take that part of the code ?codsubcategoria='.$res2['nome'].' of <li class="teste"></li>, brings me at least the tables of Brands and Categories.

I believe that something is missing in Javascript, but I have no idea what, and how I can solve this problem. I count on the help of friends.

Below I relate the codes used.

<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
    $("#menu_cat .teste a").click(function( e ){
        e.preventDefault();
        var href = $( this ).attr("href");
        $("#services").load( href +"#services");
    });
});

<ul id="menu_cat">
<?php
include "../conexao.php";
$codigo = $_POST['codigo'];
$nome_cat = $_POST['nome_cat'];
$nome = $_POST['nome'];
$query = mysql_query("SELECT codigo, nome_cat FROM categoria ORDER BY nome_cat") or die(mysql_error());

while($res = mysql_fetch_array($query)) {

    echo '<li><a href="#services">'.$res['nome_cat'].'</a>';

    $query2 = mysql_query("SELECT codigo, nome, nome_cat FROM sub_categoria WHERE nome_cat = '".$res['nome_cat']."' ORDER BY nome") or die(mysql_error());
    if(mysql_num_rows($query2) > 0) {
        echo '<ul id="menu_cat">';
        while($res2 = mysql_fetch_array($query2)) {
            echo '<li class="teste"><a href="prod_index_categoria.php?codsubcategoria='.$res2['nome'].'">'.$res2['nome'].'</a></li>';
        }
        echo '</ul>';
    }

    echo '</li>';

}
?>
</ul>

Already my thanks for the attention to my problem.

  • It is not very clear what you want...

  • How do you handle the request of Uri prod_index_categoria.php? codsubcategoria=xxxx ? And really in javascript you call prod_index_categoria.php? codsubcategory=xxx#service? Why? A hint when you make ajax requests is always good to use the browser debug tools to see the sent and received parameters (In most browsers right click - inspect element - network tab).

  • I’m trying to load the content dynamically into a div on the index without the refresh. If you want I can send the address to check what I want testing directly on the Site.

  • Send the address, or specify what you want to do and how to detail, because in the code it becomes more difficult to understand.

  • Hello @Cleverson, the address is (http://vogadesignglass.com). enter products and when you click on any of the brands it works the way you want, that is to say opening the products related to the selected brand without giving the refresh on the Site DIV id="services" which is in index.php. When the product is selected for the desired categories, it goes to the DIV, but does not even open the tables of Brands and Categories.

  • Continuing - As I reported earlier, when I remove this part of the code ?codsubcategory='. $res2['name'].' of <li class="test"></li>, brings me at least the tables of Brands and Categories. If you can give me a light on how to solve this I will be very grateful.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.