Functions remember variables in their parent scope when they're defined. This is called a closure. You can read about it here
So in order to retain a reference to the element, store the element in a variable like so:
$(".image_id_field").each(function() {
var $this = $(this), // store the jQuery element
img_id = $this.html();
$.post("ajax/get_image.php", { id: img_id }, function( response) {
// the callback function still references the $this var defined in the parent scope
$this.html(response);
});
)
I'm not sure about your second question, as the $.post call is asynchronous already.
I'd recommend learning about variable scope in more detail as in your example you were creating a global variable called img_id
.
What is the scope of variables in JavaScript?