0

I am trying to get my db rows from php. Currently the js success function isn't being reached. Is there anything obvious in the php that may be causing an issue?

The php

$id=$_GET['id'];

$stmt = $db->prepare("SELECT * FROM brand_members WHERE Id = :id");
$stmt->bindValue(':id',$id,PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($result);

The js

$.ajax({                                      
      url: 'dead.php',                  //the script to call to get data          
      data: "id=8",                      
      dataType: 'json',                //data format      
      success: function(data)          //on recieve of reply
      {
        var id = data[0];              //get id
        var vname = data[1];           //get name
        alert("a");         //get name
      }
});
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Buy Naural
  • 11
  • 4

1 Answers1

0

The problem is you didn't passed properly your $_GET parameter

To solve that

Change your

url: 'dead.php'

to

url: 'dead.php?id=8',

also data: your_data is no longer needed

Or this method change

data: "id=8"

to

data: {id: 8}

Also in your callback since your ajax response returns an array specified the index 0

success: function(data)          //on recieve of reply
  {
    var id = data[0]['Id'];              //get id
    var vname = data[0]['name'];           //get name
    alert("a"); 
  }
Beginner
  • 4,118
  • 3
  • 17
  • 26