[英]PHP/Jquery Ajax Return SQLite string
我有以下Ajax请求:
$.ajax({
type: "POST",
url: "getContent.php",
dataType: "text",
data: { "contentid": contentID },
success: function (data) {
console.log("Received: " + data );
}
});
}
哪个将单个值发送到我的PHP脚本,位于getContent.php
我认为getContent.php非常简单。 它包含:
<?php
// Set up connection to sqlite
try {
$myPDO = new PDO('sqlite:freezy.sqlite');
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
$id = $_POST['contentid'];
// Prepare an update statement
$sql = "select contentBlock from content where contentId = :contentIDTarget";
// formalise the statement
$stmt = $myPDO->prepare($sql);
// passing values to the parameters
$stmt->bindValue(':contentIDTarget', $id);
// Execute the update
$result = $stmt->execute();
echo $result;
?>
在slqite测试工具中针对同一数据库进行测试时,此sql可以正常工作。
但是,当我尝试使用此功能时,在控制台日志中“ Received:”行上看到的全部是:
收到:1
我期望看到的是:收到:
只是一些测试文字
因为结果应包含来自tinyMCE的大量内容。
我想念什么? 请多多关照。
您的声明...
$result = $stmt->execute();
只会返回布尔值。 因此,看到“ 1”是一件好事,因为它意味着它有效。
因此,您需要返回实际结果。 您可以尝试类似...
$result = $sth->fetch(PDO::FETCH_ASSOC);
转换成类似...
// Execute the update
$stmt->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
echo $result;
或echo $result['contentBlock'];
这完全取决于您要如何使用它。
这有帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.