tags:

views:

67

answers:

1

Hi guys,

I am trying to populate a table using jQuery $.post, but I keep getting (an empty string) when I log the data using firebugs console.log(), here is the code,

jQuery:

        $.each(data, function(i, json){
            //get the system names
            $.post('get_system_name.php', {product_id:json.product_id}, function(data){

                console.log(data);

            });             
        });

PHP:

$product_id = $_POST['product_id'];

mysql_connect("localhost", "user", "1234") or die(mysql_error());
mysql_select_db("eskom_products") or die(mysql_error());
$query = mysql_query("SELECT products FROM products WHERE product_id='".$product_id."'") or die(mysql_error('Please try again'));
$array = mysql_fetch_array($query, true);

echo $array['products'] ;

Initially I do a $.getJSON() request, and then I loop through all of the entries I get back using $.each, but as you can see, the name of the system is not in the same table, so I need to do a seperate $.post() to get the name in the related table, but all I get is an empty string, any ideas?

A: 

It's clear your jquery is ok, the only problem would be the value of json.product_id, that could be wrong, but I suppose it's not the problem.

Verify the database is returning something. To do that, access directly to "get_system_name.php?product_id="+PRODUCTID (change this). And change the $_POST for a $_REQUEST or $_GET.

In this way you jump the javascript step.

netadictos