Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ajax error: read record and open model window

    i trying to fetch a record from database but my ajax is failing here is the code.

    Code:
     employeeTable.find(".command-edit").on("click", function(event)
          {
           var eid = $(this).data("row-id");
        
        // At this point i can get the alert values o.k. 
        
           alert("You pressed edit on row: " + $(this).data("row-id"));
           alert("You pressed edit on row: "+""+eid);
           
        //but here is the issue
        
         $.ajax({
            url:"fetch_single.php",
            method:"POST",
            data:{eid:eid},
            dataType:"json",
        	cache: false,
            
          success: function(data){
            alert('success');
          },
        
        // its always failing.
        
          error: function(){
            alert('failure');
          }
    my fetch record php.
    Code:
        <?php
        //fetch_single.php
        
        include_once("db_connect.php");
        
        if(isset($_POST["eid"]))
        {
         //$output = array();
         
         $query = "SELECT * FROM employee WHERE id =      '".$_POST["eid"]."'";
         $result = mysqli_query($connection, $query);
         while($row = mysqli_fetch_array($result))
         {
          $output["id"] = $row["id"];
          $output["employee_name"] = $row["employee_name"];
          $output["employee_salary"] = $row["employee_salary"];
          $output["employee_age"] = $row["employee_age"];
          
         }
         echo json_encode($output);
        }
        
        ?>
    I checked the column names in the above file all looks o.k
    table name is fine.
    not sure what i am doing wrong.

  2. #2
    New to the CF scene
    Join Date
    Sep 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    *** employeeTable.find(".command-edit").on("click)
    {
    var eid = $(this).data("row-id");

  3. #3
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    7,779
    Thanks
    35
    Thanked 1,044 Times in 1,040 Posts
    @vishalsanwar, the idea of this or any forum is to solve problems in the open. Have the solution here in black and white so others may take something away with them if they have the same problem or a means to avoid the problem. It is not here so you may grab people for your own use. I am reporting you.

    @SalmanS, your problem may come from this:
    Code:
    employeeTable.find(".command-edit").on("clicknt)
    Don't think there is a clicknt. And you need to close the quotes. So try this:
    Code:
    employeeTable.find(".command-edit").on("click")
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •