 
     api: (url, data={}, type='GET') ->
         dfd = $.Deferred()
-        $.ajax(url: @root + url, data: data, type: type.toUpperCase())
+        xhr = $.ajax(url: @root + url, data: data, type: type.toUpperCase())
             .done (response) =>
                 if not response.jobid?
                     # Not a webcoroutine
+                    response.xhr = xhr
                     return dfd.resolve(response)
-                @jobs[response.jobid] = dfd
+
+                @jobs[response.jobid] = [dfd, xhr]
                 if response.pending
                     dfd.notify response.jobid
                 if response.pending and @interval > response.interval

                    @poll(1000)
                @handle_response response

            .fail (xhr, status, error) =>
                dfd.reject message: "HTTP #{xhr.status}: #{xhr.statusText}", xhr: xhr
        return dfd.promise()


    handle_response: ({jobs, notifications}) ->
        for job in jobs
            if @jobs[job.id]
                [dfd, xhr] = @jobs[job.id]
                delete @jobs[job.id]
                if job.error
                    job.error.xhr = xhr
                    dfd.reject job.error
                else
                    dfd.resolve job.result

        for n in notifications
            if @handlers[n._ntype]?
