我目前遇到一个错误,我需要将参数值从 url 传递到后端的 PHP
文件。
URL 是什么样的?p=tasks&t=view_task&id=1
。我需要将值为 1
的 id
传递到我的页面,该页面位于 url: '/core/views/task_comments.php'
.
var seconds = 1000; // time in milliseconds
var tc_reload = function() {
$.ajax({
type: 'GET',
url: '/core/views/task_comments.php',
data: {id: id},
cache: false,
success: function(data) {
$('#task-comments').html(data);
setTimeout(function() {
tc_reload();
}, seconds);
}
});
};
tc_reload();
在 PHP 页面上我得到了以下代码。
// Fetch task data
$task_fetch = $conn->prepare("SELECT * FROM system_tasks WHERE task_id = :task_id");
$task_fetch->bindValue(":task_id", $_GET['id'], PDO::PARAM_INT);
$task_fetch->execute();
我收到的是以下错误。
Notice: Undefined index: id in C:\xampp\htdocs\core\views\task_comments.php on line 19`
我很想知道出了什么问题。
最佳答案
解决了问题。
显然 config.php 文件在 id 参数后添加了 ?p=login
。
url: '/core/views/task_comments.php?id='+id+'&p=login'
修复了问题,现在可以正常工作了。
关于php - 传递 GET 并使用 GET 读取 mySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32393194/