Writing Javascript to handle ajax file file requests