fixed errors when ajax response does not contain "query" property - originally coded by SebiTimeWaster