I am trying to retrieve information from my php file which contains the following code. My code contains the colums Email, FirstName, LastName, and State.

我正在尝试从包含以下代码的php文件中检索信息。我的代码包含列电子邮件、名、名和状态。

$query = 'SELECT * FROM users WHERE LOWER(Email) = :email';
$stmt = $dbh->prepare($query);
$stmt->bindValue(':email', $email);
$stmt->execute();

if ($stmt->rowCount() == 1) {
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    $firstName = $row['FirstName'];
    $lastName = $row['LastName'];
    $state = $row['State'];     
} echo json_encode($row);

My Ajax code is:

我的Ajax代码是:

$.ajax({
    datatype: 'json',
    type: "POST",
    url: 'json-data.php',         
      success: function(data) {
        //called when successful
        $('#firstname').append(data.FirstName);     
      },
      error: function(e) {
        //called when there is an error
        //console.log(e.message);
      }

});

});

When I type $('#firstname').append(data);, it shows me the following output:

当我输入$('#firstname').append(data);

{"FirstName":"Foo","LastName":"Bar","State":"Florida","Email":"foo@bar.com"}

How do I make it so I can get only the first name and append it to a div?

如何才能只获取第一个名称并将其附加到div中呢?

1 个解决方案

#1


1

try with:

试一试:

var obj = jQuery.parseJSON(data);
$('#firstname').append(OBJ.FirstName); 

更多相关文章

  1. Webhoster插入了一个javascript,它会阻止我的代码如何删除它?
  2. 可以直接拿来用的15个jQuery代码片段
  3. 为什么使用observe_field代码不能使用JQuery模型对话框?
  4. jquery 生成table表格 部分代码
  5. 使用jquery的$ .ajax来获取node.js脚本的输出,而不是它的代码
  6. 为什么jQuery的电子邮件验证regex如此简单?
  7. Server.Htmlencode用于文本域显示带的html代码
  8. IOS学习之WebView加载本地HTML代码或网络资源
  9. html5 css3 背景视频循环播放代码

随机推荐

  1. 报错pymysql.err.DataError: (1406, "Dat
  2. 请教用sql loader导入数据,最后一位是整数
  3. JDBC连接并使用mysql数据库
  4. SQL Server 2008使用sproc中的函数
  5. 如何在ACCESS中接收SQL SERVER返回结果集
  6. 脚本与SQL Server中的表并发运行
  7. logstash-jdbc-input与mysql数据库同步
  8. 求查询成绩表中两门科成绩90分以上的学生
  9. SQL Server Reporting Services图表查询
  10. Python将MySQL表数据写入excel