Yes, it is possible. You would need to pass the post ID to your function so that it could get the next item. Along with which you want to get.
A better choice, I think, than ajax would be to add it with just JavaScript. You could create a script that swaps the image and then using wp_localize_script()
https://codex.wordpress.org/Function_Reference/wp_localize_script you can add information about all of the images.