Abstracted out queryRun function for running ajax queries