   console.log "Query: #{query}"
   switch query.split(' ')[0]
     when 'INSERT'
-      $.ajax "#{FUSION_TABLES_URI}/query?access_token=#{get_cookie 'access_token'}",
+      $.ajax "#{FUSION_TABLES_URI}/query",
         type: 'POST'
         dataType: 'json'
         crossDomain: true
+        beforeSend: (xhr) ->
+          xhr.setRequestHeader('Authorization',"Bearer #{get_cookie 'access_token'}")
         data:
           sql: query
         error: (jqXHR, textStatus, errorThrown) ->

check_table_access = (table_id, callback) ->
  # test table access
  if get_cookie 'access_token'
    $.ajax "#{FUSION_TABLES_URI}/tables/#{table_id}?access_token=#{get_cookie 'access_token'}",
      type: 'GET'
      dataType: 'json'
      crossDomain: true
      error: (jqXHR, textStatus, errorThrown) ->
        console.log "AJAX Error: #{textStatus}"
        $('.container > h1').after $('<div>').attr('class','alert alert-error').attr('id','collection_access_error').append('You do not have permission to access this collection.')

          if callback?
            callback(data)
    when 'SELECT'
      $.ajax "#{FUSION_TABLES_URI}/query?sql=#{query}",
        type: 'GET'
        cache: false
        dataType: 'json'
        crossDomain: true
        beforeSend: (xhr) ->
          xhr.setRequestHeader('Authorization',"Bearer #{get_cookie 'access_token'}")
        error: (jqXHR, textStatus, errorThrown) ->
          console.log "AJAX Error: #{textStatus}"
        success: (data) ->
