       catch err
         console.error "kdb-srv: HTTP callback exception"
         console.log err
-    q = @qPrefix + encodeURIComponent q
-    q = q + "&target=" + trg if @target and trg=extractInfo @target
-    console.log "kdb-srv sending request:"+q if @debug
     xhr.open 'GET', q, true, @srvUser, @srvPass
     xhr.send()
+  sendJSONP: (rid,q,cb) ->
+    resOk = false
+    jsonpRegistry[rid] = (res) =>
+      console.log "kdb-srv(jsonp) data: " + res.toString().slice(0,50) if @debug
+      delete jsonpRegistry[rid]
+      resOk = true
+      try
+        cb res, null
+      catch error
+        console.error "kdb-srv: HTTP callback exception"
+        console.log error
+    script = document.createElement('script')
+    script.onload = script.onerror = =>
+      return if resOk
+      delete jsonpRegistry[rid]
+      console.log "kdb-srv(jsonp): error" if @debug
+      try
+        cb null, "url: "+q
+      catch error
+        console.error "kdb-srv: HTTP callback exception"
+        console.log error
+    script.src = q
+    document.body.appendChild script
 
 class _KDBQuery extends HTMLElement
   createdCallback: ->

  catch err
    null


class _KDBSrv extends HTMLElement
  createdCallback: ->

  onexec: (f) -> @addEventListener 'execText', f

window.KDB ?= {}
KDB.processJSONP = (id,res) ->
  console.log "kdb-srv(JSONP): #{id}" + res if @debug
  jsonpRegistry[id]?(res)
KDB.KDBChart = document.registerElement('kdb-chart', prototype: _KDBChart.prototype)
KDB.KDBSrv = document.registerElement('kdb-srv', prototype: _KDBSrv.prototype)
KDB.KDBQuery = document.registerElement('kdb-query', prototype: _KDBQuery.prototype)
