encode key before sending the ajax request