2015-09-04 50 views
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我很想知道哪里出了错误

+3

你在代码中定义'id'的位置? – Saty

+0

它应该是'id'而不是'task_id'。更新代码@Saty – Tweath

+0

@Samuel是来自id集的JavaScript的值? – Cosmin

回答

0

解决了这个问题。

很明显,config.php文件在id参数后面添加了?p=loginurl: '/core/views/task_comments.php?id='+id+'&p=login'修复了这个问题,它现在的工作方式应该是这样。