I using Javascript and Ajax for sending and receiving data from the server. I read some where that its some error in the server file that why its giving this error but I can't find any.
My html file
<select class="form-control" id="semester" name="semester">
    <option value=-1>Select Semester</option>
    <option value=1>Semester </option>
    <option value=1>Semester 1</option>
    <option value=2>Semester 2</option>
    <option value=3>Semester 3</option>
    <option value=4>Semester 4</option>
    <option value=5>Semester 5</option>
    <option value=6>Semester 6</option>
    <option value=7>Semester 7</option>
    <option value=8>Semester 8</option>
</select>
<<select class="form-control" id="category_id" name="category_id">
    <option value=-1>Select Catagory</option>
    <option value=1>Institutional Reqt.</option>
    <option value=2>Adv. Core</option>
    <option value=3>Foundation</option>
    <option value=4>Adv. Elect</option>
</select>
<input class="btn btn-primary" type='button' id='find' value='find' name="find">
</form>
<table>
    <tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Job Title</th>
    </tr>
    <tbody id="data">
    </tbody>
</table>
My JavaScript file
This is the send the semester number and the category that the user wants to see.
  <script>
        $("#find").click(function(){
        var semester=$("#semester").val();
        var category_id=$("#category_id").val();
        $.ajax({
                url:'data.php',
                type:'GET',
                data:{semester:semester,category_id:category_id},
                success:function(data){
                    console.log(data);
                    if(data==1){
                        console.log("Very noice");
                    }
                }
            })  
        });
This is to receive the information from the server.
        //call ajax
    var ajax= new XMLHttpRequest();
    var method='POST';
    var url = 'data.php';
    var asynchronous = true;
    ajax.open(method, url, asynchronous);
// sending ajax request
    ajax.send();    
//receiving response from data.php
    ajax.onreadystatechange = function(){
        if(this.readyState == 4 && this.status == 200)
        {
            //converting JSON back to array
            var data = JSON.parse(this.responseText);
            console.log(data); 
            var html = "";
            //loopinh through the data
            for(var a=0;a<data.length;a++){
                var firstName=data[a].semester;
                var lastName=data[a].course_title;
                var jobTitle = data[a].course_desc;
                html += "<tr>";
                html += "<td>" + firstName + "</td>";
                html += "<td>" + lastName + "</td>";
                html += "<td>" + jobTitle + "</td>";
                html += "</tr>";
                document.getElementById("data").innerHTML = html; 
            }
        }
    }
</script>
and here is my php file
<?php
//getting data from database
$conn = mysqli_connect("localhost","root","","bscis1620");
$semester = $_GET['semester'];
$category_id= $_GET['category_id'];
    $query = 'select * from bscis1620';
    $check = 0;
    $semesterq="$semester = bscis1620.semester";
    $category_idq="$category_id = bscis1620.category_id";
    if($semester>0){
        if($check == 0){
            $query = $query. " where ". $semesterq;
            $check++;
        }
        else{
            $query = $query. " and ". $semesterq;
        }
    }
    if($category_id>0){
        if($check == 0)
            $query = $query. " where ". $category_idq;
        else{
            $query = $query. " and ". $category_idq;
        }
    }
    $result=mysqli_query($conn, $query);
$data = array();
while($row = mysqli_fetch_assoc($result))
{
    $data[] = $row;
}
echo json_encode($data);
?>
I have check my query by console.log and I get the correct information from the database, I'll really appreciate any help.
