Unless your API is returning a complete HTML page - which isn't normal for an API - it cannot change the source of an HTML element in your page.
Assuming you're using an AJAX/fetch request to submit the form to the API, your Javascript can then change the image source when the request completes.
Fetch API - Web APIs | MDN[
^]