Click here to Skip to main content
15,884,605 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<script>
jQuery(document).ready(function()
{
    jQuery.ajax(
    {
        type: 'GET',
        url: 'specificationTypes.php',
        dataType: 'JSON',
        success:function(data)
        {
                    for(i=0;i<jQuery(data).length;i++)
            {
                $('#specificationType').append('<option value = '+ data[i].specification_type_id+'>' + data[i].specification_type_name + '</option>');
            }
        }
    });
});
</script>

<script>
jQuery(document).ready(function()
{
    jQuery('#specificationType').change(function()
        {
            var specificationType = jQuery("#specificationType").val();

            var jsonString = JSON.stringify(specificationType);

            jQuery.ajax(
            {
                type:"POST",
                url:"specifications.php",
                data: {data : jsonString},
                cache: false,
                success:function(data)
                {
                    for(i=0;i<jQuery(data).length;i++)
                    {
                        jQuery("#specifications").append('<option value = '+ data[i].project_specification_details+'>' + data[i].project_specification_details + '</option>');

                        console.log('success');
                    }
                }
            });
    });
});
</script>


my .php file

PHP
<?php
    mysql_connect("localhost","root","myfourwalls");

    mysql_select_db("new_project");

    $specificationType = json_decode(stripslashes($_POST['data']));
    $result = mysql_query("SELECT DISTINCT project_specification_details FROM project_specifications WHERE project_specification_type IN(".implode(",",$specificationType).")");

    $specifications = array();

    while ($data = mysql_fetch_array($result,MYSQL_ASSOC)) {

    $data_array['project_specification_details'] = $row['$project_specification_details'];

    array_push($specifications,$data);
    }
    $data = json_encode($specifications);

    echo $data;
?>


I got the JSON data to the variable called data but cant append it to the UI.Some error is coming in the console.
Posted

1 solution

What error are you seeing in the console? But at the top of my head look at

$('#specificationType').append('<option value = '+ data[i].specification_type_id+'>' + data[i].specification_type_name + '</option>');


Consider replacing it with

JavaScript
jQuery("#specifications").append('<option value = "'+ data[i].project_specification_details+'">' + data[i].project_specification_details + '</option>');
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900