从$.ajax调用运行PDO语句时出现问题


Issue with running a PDO statement from a $.ajax call

嘿,伙计们,我有以下ajax调用:

function sendUserfNotes()
{
    $.ajax({
    type: "POST",
    dataType: "json",
    url: '/pcg/popups/getNotes.php',
    data:
    {
        'nameNotes': notes_name.text(),
    },
    success: function(response) {
        $('#notes_body').text(response.the_notes);
        alert(response.the_notes);
        //$('#notes_body').html(data);
    }
});

一旦运行并转到该文件:……

try {  
  # MySQL with PDO_MYSQL  
  $DBH = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);  
  $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}  
catch(PDOException $e) { 
    echo "I'm sorry, I'm afraid I can't do that.";  
    file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);   
}
$username_notes = $_POST['nameNotes'];
$sql = "SELECT notes FROM csvdata WHERE username = :username";
$getmeminfo = $DBH->prepare($sql);
$getmeminfo->execute(array(':username' => $username_notes));
$row = $getmeminfo->fetch(PDO::FETCH_ASSOC);
$notes = $row['notes'];
$returnArray = array( 'the_notes' => $row['notes']);
echo json_encode($returnArray);
$DBH = null;

现在,在这里,一旦返回json数组,$('#notes_body').text(response.the_notes);将使用返回的响应更改div,但我的问题是我无法让它返回。它总是空的?

我不确定出了什么问题,所以如果你能这么友善,给我一些时间:)

David

更新:

因此,有一件事是我自己测试了pdo语句,它是有效的。

如果我只是给$username_notes一个像"BillCosby"这样的直接名称,它会为那个人返回正确的值。

不存在类似"$.ajax中的PDO问题"这样的问题。PDO是服务器端,而$.aajax是客户端。

就好像pdo语句根本不运行一样?

没人知道
除了你,没有人可以访问你的代码
所以,你必须自己回答。调试代码。

对于客户端调试来说,Firebug是无价的
打开它的Net选项卡,看看是否有HTTP调用。如果是的话,它有回报吗
打开Console,查看是否有任何错误。