An 0 Newbie Poster

Hi, I start learning javascript and ajax currently. The code index.php below is perform Ajax

 <!--- AJAX --->
                function showData(str)
                        if (str=="")
                        if (window.XMLHttpRequest)
                        {// code for IE7+, Firefox, Chrome, Opera, Safari
                                xmlhttp=new XMLHttpRequest();
                        {// code for IE6, IE5
                                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                                if (xmlhttp.readyState==4 && xmlhttp.status==200)

Next is the select dropdown menu perform query from my database and the script that will return the data within JSON object that will need for later use

 <select name="users" onchange="showData(this.value)">
                                <option value="">---Select Project---</option>
                                        // query projects
                                        $query_pr=mysql_query("SELECT * FROM GeneralInfo");
                                        // get project names and its corresponding revision number
                                                echo '<option value="'.$pr['pRevNum'].'">'.$pr['pName'].'</option>';

                                <!---jquery: ajax method--->
                                <script src=""></script>
                                                        $.getJSON("getData.php", function(obj) {
                                                                $.each(obj, function(key, value) {
                        // Interested DATA will be displayed here
                        // but THIS IS WHERE I WANT THE DATA TO SHOW
                        // not WORK YET !!!
                        <button>GET DATA</button>

This is my getData.php

        header('Content-Type: application/json');

        // establish connection

        // select the database

        $query ="SELECT DISTINCT BranchInfo.bName, BranchInfo.bRevNum, GeneralInfo.pName, GeneralInfo.pRevNum,BranchItemInfo.bIName, BranchItemInfo.bIRevNum
                         FROM `GeneralInfo`
                         INNER JOIN `BranchInfo`
                         ON GeneralInfo.bName=BranchInfo.bName 
                         AND GeneralInfo.bRevNum=BranchInfo.bRevNum
                         INNER JOIN `BranchItemInfo`
                         ON BranchInfo.bIName=BranchItemInfo.bIName 
                         AND BranchInfo.bIRevNum=BranchItemInfo.bIRevNum
                         AND GeneralInfo.pRevNum= '".$q."'";

        // initialize variable with the query
        $result = mysqli_query($connection,$query);

        // fectching data into array
        while($info = mysqli_fetch_array($result))
                // convert to integer value if there is a bug after passing json_encode

        // json encode
        echo json_encode($my_arr);

        // close connection

By using Ajax, I can be able to display correct data from my Database according to select option in the dropdown menu. However it is jump to the issue that I could not retrieve the specific data from Json Object after encod'ing within the getData.php. I visit my getData.php from a browser directly and I dont see the Json content, I know that it supposes to have the Json content after encod'ding cuz I have tested some examples before. Also I have noticed that the Json content is actually display on my index.php
I want to retrieve specific data from the Json Object after all. Please help me out, I really appreciates your time !!


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.