0
我目前停留在需要将URL中的参数值传递到后端PHP
文件的问题上。通过GET并使用GET读取mySQL
什么URL看起来像?p=tasks&t=view_task&id=1
。我需要将id
的值1
传递到我的页面,该页面位于例如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();
我收到的是以下错误。
注意:未定义指数:ID在C:\ XAMPP \ htdocs中\上线19`
核心\意见\ task_comments.php我很想知道哪里出了错误。
你在代码中定义'id'的位置? – Saty
它应该是'id'而不是'task_id'。更新代码@Saty – Tweath
@Samuel是来自id集的JavaScript的值? – Cosmin