move json request outside click event