1

I want to populate a database result in an HTML table. When the <a class="editUsers"> is clicked a box should pop up to show data from an Ajax call.

This should be shown:

<table id="userInfo">
    <tr>
        <thead>
            <td>User</td>
            <td>Mail</td>
            <td>Admin Access</td>
        </thead>
    </tr>
    <tr>
        <td>Jane Doe</td>
        <td>[email protected]</td>
        <td>Yes</td>
    </tr>
</table>        

$(".editUsers").click(function(){
    $("#userInfo").fadeIn(1000);
    $(".exitUsrMgmt").fadeIn(1000); //This is the close button for that popup

    $.ajax({    //create an ajax request to load_page.php
        type: "GET",
        url: "includes/getUserData.php",             
        dataType: "html",   //expect html to be returned                
        success: function(response){                   
            ("#userInfo").html(response);
        },
        error:function (xhr, ajaxOptions, thrownError){
            alert(thrownError);
        }
    });
}); 

<?php
  include_once('config.php');

  //Create PDO Object
  $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
  //Set Error Handling for PDO
  $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  //Query
  $sql = "SELECT name, email, admin FROM user_admin";

  //Prepare Statement
  $stmt = $con->prepare($sql);
  $stmt->execute();

  while ($row = $stmt->fetch()){
    echo '<tr>';
    echo    '<td>'.$row[0].'</td>';
    echo    '<td>'.$row[1].'</td>';
    echo    '<td>'.$row[2].'</td>';
    echo '</tr>';
  }
?>
3
  • 2
    For starters, ("#userInfo").html(response); is missing a $. Should be $("#userInfo").html(response); Commented Oct 21, 2015 at 16:08
  • 1
    Wow. I could hit myself with a brick right now. I looked at that code for like 30 minutes and didn't find that silly mistake. Everything works now. Thanks :) Commented Oct 21, 2015 at 16:10
  • May this helps you: stackoverflow.com/questions/30770664/… Commented Oct 21, 2015 at 16:12

1 Answer 1

1

Problem was fixed. I did a silly mistake and forgot to include a $. Thanks to Paul Roub for the answer, I quote:

For starters, ("#userInfo").html(response); is missing a $. Should be $("#userInfo").html(response); – Paul Roub 8 mins ago

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.