Handle case where pendingAjaxRequests is negative

Somehow the pendingAjaxrequests is sometimes negative. This causes the wait te wait forever. This fixes that problem