0

This is my all code. I create a modal in. In modal there are two fields. one is category name and the second is a select field. I am here want to show option list from server data using ajax. I first write the code in ajax and pass the information in process.php page. In process.php i getting error undefined index. if i commented this line then everything working well

<div class="modal fade" id="form_catagory" tabindex="-1" aria-labelledby="form_catagory" aria-label="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"> Catagory </h5>
                <button class="close" data-dismiss="modal" aria-label="close"> <span aria-hidden="true"> 
                &times;</span> </button>
            </div>

            <div class="modal-body">
                <form method="post" id="form_category" onsubmit="return false">
                    <div class="form-group">
                        <label for="category_name"> Category name </label>
                        <input type="text" name="category_name" id="category_name" class="form-control" placeholder="Enter category name" />
                    </div>
                    <div class="form-group">
                        <label for="parent_category"> Parent Category </label>
                        <select  class="form-control" name="parent_category" id="parent_category">
                            <option value="0"> root </option>
                        </select>
                    </div>
                </form>
            </div>

            <div class="modal-footer">
                <button class="btn btn-success" data-dismssiss="modal"> close </button>
            </div>
        </div>
    </div>
</div>

<script>
fetch_category();
function fetch_category() {
    $.ajax({
    url:    var DOMAIN = "http://localhost/Inv_management/public_html";
    + "/include/process.php",
    method: "POST", 
    data: {getCategory:1},
    success: function(data) {
        console.log(data);
        $("#parent_category").html(data);
        }

    })
}
</script>

<?php
if($_POST["getCategory"]) {  //  I getting error here undefined index  
    $obj = new DBOperation();
    $rows = $obj->getAllRecord("categories");
    foreach($rows as $row) {
    print_r($row['category_name']);

    }
    exit();
}  
?>

0 Answers0