我目前陷在一个错误中,我需要将参数值从url传递到后端的PHP
文件。
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();
我收到以下错误。
注意:未定义的索引:第19行的C:\ xampp \ htdocs \ core \ views \ task_comments.php中的ID。
我很想知道出什么问题了。
最佳答案
解决了问题。
显然config.php文件在id参数后面添加了?p=login
。url: '/core/views/task_comments.php?id='+id+'&p=login'
解决了该问题,现在可以正常运行了。