Could it be that the drupal database doesn't work anymore after using jquery .load()
Most likely that drupal database API is not available in your page.php file because corresponding files are not included in it. What I usually do if I want to do stuff like this, is declaring a menu item:

function MYMODULE_menu(){
    $items['path/page'] = array(
        'type' =&gt; MENU_NORMAL_ITEM,
        'page callback' =&gt; 'your_function_name',
        'title' =&gt; 'AJAX: Page callback'
    );
    return $items;
}


the code above adds a new page to drupal menu system and makes it available as: http://www.yoursite.com/path/page

and then in your function

function your_function_name() {
    $query = db_select('course_function', 'f');
    $query-&gt;fields('f', array('id'))
          -&gt;condition('f.chapter_id', $id, '=');
    $result = $query-&gt;execute();
    print_r($result);
    foreach ($result as $res) {
        $id = $res-&gt;id;
    }
    echo $id;
    //You need to have exit in such callback functions to prevent drupal theme 
    //functions from taking over the page processing
    exit;
}    


Then in your javascript you can approach this page just like this:

&lt;script type='text/javascript'&gt;            
function loadPage (id,level) {
$.ajax({   
      beforeSend: function () {   
        // here you can do things before the action start    
      },
      success: function () {
          $('#contenpage').load("http://yoursite.com/pages/page", { 'var': [id,level]})
      }
    });
} 
&lt;/script&gt;